Class: OfficialFM::Client
- Inherits:
-
Object
- Object
- OfficialFM::Client
- Defined in:
- lib/officialfm/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#api_url ⇒ String
Provides the URL for accessing the API.
-
#connection(options = {}) ⇒ Faraday::Connection
Faraday::Connection used for all HTTP requests.
- #default_headers ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Projects
#project, #project_playlists, #project_tracks, #projects
Methods included from Playlists
#playlist, #playlist_tracks, #playlists
Methods included from Tracks
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/officialfm/client.rb', line 12 def initialize(={}) @api_key = [:api_key] || OfficialFM.api_key connection() end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/officialfm/client.rb', line 10 def api_key @api_key end |
Instance Method Details
#api_url ⇒ String
Provides the URL for accessing the API
53 54 55 |
# File 'lib/officialfm/client.rb', line 53 def api_url "http://api.official.fm" end |
#connection(options = {}) ⇒ Faraday::Connection
Faraday::Connection used for all HTTP requests
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/officialfm/client.rb', line 21 def connection(={}) config = { :url => api_url, :headers => default_headers }.merge() @connection ||= Faraday.new(config) do |builder| builder.adapter Faraday.default_adapter builder.request :url_encoded builder.response :mashify builder.response :json end end |
#default_headers ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/officialfm/client.rb', line 39 def default_headers headers = { 'X-API-Version' => '2.0', :accept => 'application/json', :user_agent => "officialfm v2 ruby gem version #{OfficialFM::VERSION}" } headers['X-API-KEY'] = @api_key if @api_key headers end |