Module: TheCastleClient

Defined in:
lib/the_castle_client.rb,
lib/the_castle_client/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def host
  @host
end

.keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def key
  @key
end

.portObject

Returns the value of attribute port.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def port
  @port
end

.schemeObject

Returns the value of attribute scheme.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def scheme
  @scheme
end

.secretObject

Returns the value of attribute secret.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def secret
  @secret
end

.versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/the_castle_client.rb', line 8

def version
  @version
end

Class Method Details

.account_aggregates(id) ⇒ Object



26
# File 'lib/the_castle_client.rb', line 26

def (id); query(id, 'account', 'aggregates'); end

.account_data(id, opts = {}) ⇒ Object

these are just niceties around the query method; deprecate?



25
# File 'lib/the_castle_client.rb', line 25

def (id, opts={}); query(id, 'account', '', opts); end

.piece_aggregates(id) ⇒ Object



28
# File 'lib/the_castle_client.rb', line 28

def piece_aggregates(id); query(id, 'piece', 'aggregates'); end

.piece_data(id, opts = {}) ⇒ Object



27
# File 'lib/the_castle_client.rb', line 27

def piece_data(id, opts={}); query(id, 'piece', '', opts); end


16
17
18
19
20
21
22
# File 'lib/the_castle_client.rb', line 16

def popular_pieces(popular_on=Date.today, limit=25)
  popular_on = Date.parse(popular_on) if popular_on.is_a?(String)
  popular_on_s = popular_on.to_s
  options = {'popular_on'=>popular_on_s, 'limit'=>limit}
  url = "/api/#{version}/pieces/popular#{to_query(options)}"
  get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
end

.query(id, model = 'account', data_type = '', options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/the_castle_client.rb', line 10

def query(id, model='account', data_type='', options={})
  raise "Invalid data type #{data_type}" unless ['aggregates', 'referrers', 'embedders', ''].include?(data_type)
  url = "/api/#{version}/#{model}s/#{id}/#{data_type}#{to_query(options)}"
  get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
end