I want to make a simple call using an API. I tried implementing ActiveResource, which may have been deprecated (see here: Consuming REST API from Rails Application).
I already have an access token for the API, and when I step through the process from the console (see quick start guide: https://github.com/teamsnap/apiv2-docs/wiki/1.-Authentication), I can get things to work (like adding a new team). However, I can't seem to figure out how to implement it in Rails. I want to start with something simple like displaying my team names on a page - that's it!
Here is the API info: https://github.com/teamsnap/apiv2-docs/wiki/Getting-Started-Guide .
I think since I already have a token (that I got via the command line tutorial), I don't need to include my username and password every time. This could be incorrect.
If someone could please give me details on how to set this up, I would greatly appreciate it! I am fairly new to rails, so feel free to give as much info as possible. Thank you!
EDIT: Thanks to Uri, it's working. To create a simple test of the API, I created a blank show.html.erb page. In teams_controller.rb, I added Uri's code into a "show" method, and add routes, as set forth below:
teams_controller.rb
def show
RestClient.post("https://api.teamsnap.com/v2/teams", '{"team": {"team_name": "Braves", "sport_id": 1,
"timezone": "Mountain Time (US & Canada)", "country": "United States", "zipcode": 80302}}',content_type: :json,
x_teamsnap_token: 'your_token_goes_here_in_quotes')
end
routes.rb
get 'teams/show'
post 'teams/show'
To test the api, navigate your browser to localhost:3000/teams/show . This will manually 'fire' the show method for you. Go back to your Teams Dashboard at Teamsnap (http://go.teamsnap.com/team/dashboard). You should now have a new team called 'Braves' (see Braves name in code above)! Now that I know it's working, I can move on to other features like creating teams in my app and sending that information to TeamSnap, instead of hard-coding it as set forth above.