Class: OfficialFM::Client
- Inherits:
-
Object
- Object
- OfficialFM::Client
- Extended by:
- Forwardable
- Includes:
- Authentication, Playlists, Tracks, Users
- Defined in:
- lib/officialfm/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
Instance Method Summary collapse
-
#api_url ⇒ String
Provides the URL for accessing the API.
-
#connection ⇒ Faraday::Connection
Raw HTTP connection, either Faraday::Connection.
- #default_headers ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#simple_params(options = nil) ⇒ Object
GET request arguments for simple API calls.
Methods included from Playlists
#improve, #playlist, #playlist_create!, #playlist_picture!, #playlist_remove!, #playlist_unvote!, #playlist_vote!, #playlist_votes, #playlists, #update_playlist!
Methods included from Tracks
#add_track_to_playlist!, #charts, #latest, #remove_track_from_playlist!, #track, #track_picture!, #track_unvote!, #track_vote!, #track_votes, #tracks, #update_track!, #upload!
Methods included from Users
#dropbox, #newsfeed, #own_playlists, #own_tracks, #picture!, #profile, #subscribe!, #unsubscribe!, #update_profile!, #user, #user_contacts, #user_playlists, #user_subscribers, #user_subscriptions, #user_tracks, #users, #voted_playlists, #voted_tracks
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/officialfm/client.rb', line 19 def initialize(={}) @api_key = [:api_key] || OfficialFM.api_key @api_secret = [:api_secret] || OfficialFM.api_secret @access_token = [:access_token] @access_secret = [:access_secret] # Note: Although the default of the API is to return XML, I think # json is more appropriate in the Ruby world @format = [:format] || :json connection unless @access_token end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/officialfm/client.rb', line 15 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
15 16 17 |
# File 'lib/officialfm/client.rb', line 15 def api_secret @api_secret end |
Instance Method Details
#api_url ⇒ String
Provides the URL for accessing the API
86 87 88 |
# File 'lib/officialfm/client.rb', line 86 def api_url "http://api.official.fm" end |
#connection ⇒ Faraday::Connection
Raw HTTP connection, either Faraday::Connection
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/officialfm/client.rb', line 55 def connection params = = { :url => api_url, :headers => default_headers } @connection ||= Faraday.new() do |builder| builder.use Faraday::Request::OfficialFMOAuth, authentication if authenticated? builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded builder.use Faraday::Response::Mashify builder.use Faraday::Response::ParseJson builder.adapter Faraday.default_adapter end end |
#default_headers ⇒ Object
76 77 78 79 80 81 |
# File 'lib/officialfm/client.rb', line 76 def default_headers headers = { :accept => 'application/json', :user_agent => "officialfm ruby gem version #{OfficialFM::VERSION}" } end |
#simple_params(options = nil) ⇒ Object
GET request arguments for simple API calls
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/officialfm/client.rb', line 32 def simple_params ( = nil) params = { :key => @api_key, :format => @format, } if .each { |key, value| case key when 'limit' params['api_max_responses'] = value when 'embed' params['api_embed_codes'] = value else params[key] = value end } end params end |