Class: Billboard::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/billboard/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Get your api_key found here developer.billboard.com/apps/register



10
11
12
13
14
15
16
# File 'lib/billboard/client.rb', line 10

def initialize(api_key=nil)
  @api_key = api_key
  @api_key ||= Billboard.api_key
  
  @api_path = ''

end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/billboard/client.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#chart(id, query = {}) ⇒ Object

Get chart data based on chart ID

Parameters

id  String


47
48
49
50
51
52
# File 'lib/billboard/client.rb', line 47

def chart(id, query={})
  chart = Mash.new(self.class.get('/item', :query => {:id => id}.merge(query).merge(self.default_options))).chart
  chart.rubyify_keys!
  chart.chart_items.items = chart.chart_items.delete('chart_item')
  chart
end

#chart_specs(query = {}) ⇒ Object

This resource returns data on the different chart names and chart types.

The API orders the results ascending by ChartSpecId.

Parameters

name   string(optional)  chart name, for example: The Billboard Hot 100
type   string(optional)  chart type, for example: Singles


64
65
66
67
68
69
# File 'lib/billboard/client.rb', line 64

def chart_specs(query={})
  results = Mash.new(self.class.get('/list/spec', :query => query.merge(self.default_options))['chartSpecs'])
  results.rubyify_keys!
  results.charts = results.delete('chart_spec')
  results
end

#search(query = {}) ⇒ Object

Use this resource to search Billboard data for chart items by id, by date, by artist, or by song.

Parameters:

id          string(optional)  Chart spec(format) id - this can be retrieved by spec service
start_date  string(optional)  Chart issue date range start
end_date    string(optional)  Chart issue date range end
artist      string(optional)  Artist name to search
song        string(optional)  Song name to search

start       default: 1              Start position of raw ResultSet
count       default: 50             number of data might be returned. Maximum 50
sort        default: date-, name+   Sort order desired, with "+" or "-" suffix to indicate ascending or descending. For example, date+


33
34
35
36
37
38
# File 'lib/billboard/client.rb', line 33

def search(query={})
  results = Mash.new(self.class.get('/list', :query => scrub_query(query))['searchResults']).rubyify_keys!
  results.chart_items = results.delete('chart_item')
  results.chart_items = [] if results.chart_items.nil?
  results
end