the_castle_client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module TheCastleClient
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,23 +7,9 @@ module TheCastleClient
7
7
 
8
8
  attr_accessor :key, :secret, :scheme, :host, :port, :version
9
9
 
10
- def account_data(account_id, options={})
11
- url = "/api/#{version}/accounts/#{account_id}#{to_query(options)}"
12
- get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
13
- end
14
-
15
- def account_aggregates(account_id)
16
- url = "/api/#{version}/accounts/#{account_id}/aggregates"
17
- get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
18
- end
19
-
20
- def piece_data(piece_id, options={})
21
- url = "/api/#{version}/pieces/#{piece_id}#{to_query(options)}"
22
- get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
23
- end
24
-
25
- def piece_aggregates(piece_id)
26
- url = "/api/#{version}/pieces/#{piece_id}/aggregates"
10
+ def query(id, model='account', data_type='', options={})
11
+ raise "Invalid data type #{data_type}" unless ['aggregates', 'referrers', 'embedders', ''].include?(data_type)
12
+ url = "/api/#{version}/#{model}s/#{id}/#{data_type}#{to_query(options)}"
27
13
  get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
28
14
  end
29
15
 
@@ -35,6 +21,12 @@ module TheCastleClient
35
21
  get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
36
22
  end
37
23
 
24
+ # these are just niceties around the query method; deprecate?
25
+ def account_data(id, opts={}); query(id, 'account', '', opts); end
26
+ def account_aggregates(id); query(id, 'account', 'aggregates'); end
27
+ def piece_data(id, opts={}); query(id, 'piece', '', opts); end
28
+ def piece_aggregates(id); query(id, 'piece', 'aggregates'); end
29
+
38
30
  protected
39
31
 
40
32
  [:delete, :get, :head, :post, :put, :request].each do |method|
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestTheCastleClient < Test::Unit::TestCase
4
-
4
+
5
5
  def setup
6
6
  TheCastleClient.key = '9NmQzsWBWs8TyfJswqMmkmjwAH3ItNBIC72KLjQK'
7
7
  TheCastleClient.secret = '592BSoaCb4FfwqsZ6Ql8WShVZ6HVnecR4Dk9lRfQ'
@@ -9,27 +9,37 @@ class TestTheCastleClient < Test::Unit::TestCase
9
9
  TheCastleClient.port = 3000
10
10
  TheCastleClient.version = 'v1'
11
11
  end
12
-
12
+
13
13
  def test_account_data
14
14
  response = TheCastleClient.account_data(7018, {:scale=>'week', :start_on=>'2010-01-01', :end_on=>'2010-04-01'})
15
15
  puts response.read_body
16
16
  end
17
17
 
18
+ def test_account_embedders
19
+ response = TheCastleClient.query(128129, 'account', 'embedders', {:scale=>'week', :start_on=>'2011-10-24', :end_on=>'2011-11-02'})
20
+ puts response.read_body
21
+ end
22
+
23
+ def test_account_referrers
24
+ response = TheCastleClient.query(128129, 'account', 'referrers', {:scale=>'week', :start_on=>'2011-10-24', :end_on=>'2011-11-02'})
25
+ puts response.read_body
26
+ end
27
+
18
28
  def test_account_aggregates
19
29
  response = TheCastleClient.account_aggregates(7018)
20
30
  puts response.read_body
21
31
  end
22
-
32
+
23
33
  def test_piece_aggregates
24
34
  response = TheCastleClient.piece_aggregates(37745)
25
35
  puts response.read_body
26
36
  end
27
-
37
+
28
38
  def test_piece_data
29
39
  response = TheCastleClient.piece_data(37745, {:scale=>'week', :start_on=>'2010-01-01', :end_on=>'2010-04-01'})
30
40
  puts response.read_body
31
41
  end
32
-
42
+
33
43
  def test_popular_pieces
34
44
  response = TheCastleClient.popular_pieces(Date.parse('2011-01-03'), 10)
35
45
  puts response.read_body
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_castle_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - kookster
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-11 00:00:00 -04:00
18
+ date: 2011-12-01 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency