the_castle_client 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f5675741562106bb9cc16b80567d1c69e0d548c
4
+ data.tar.gz: 9dc42bfd20f2714463ce2a636d0631689282d541
5
+ SHA512:
6
+ metadata.gz: 8a051e5c341b4e2b8f4c0487a0746cb80d25d4bba063d534c92ce8a2d9fcb7c91da7121f24b2ecb6b4ba7c003c5775d5f7afedf5890390d8e7394278cf539afe
7
+ data.tar.gz: 70d0ea86db29509d04c0cb9a5e61b77b1e6612713281e7f6ab2727e38795821a443709a2ffb2cad067b832d061a384cfe68ae1c2267f1e65a352f98d213c4a8e
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .env
6
+ .ruby-version
7
+ .DS_Store
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  require 'bundler'
2
+ require 'rake/testtask'
3
+
2
4
  Bundler::GemHelper.install_tasks
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/test_*.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
@@ -7,9 +7,10 @@ module TheCastleClient
7
7
 
8
8
  attr_accessor :key, :secret, :scheme, :host, :port, :version
9
9
 
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)}"
10
+ def most_listened_pieces(most_on=Date.today, limit=25)
11
+ most_on = Date.parse(most_on) if most_on.is_a?(String)
12
+ options = {'most_on'=>most_on.to_s, 'limit'=>limit}
13
+ url = "/api/#{version}/pieces/most_listened#{to_query(options)}"
13
14
  get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
14
15
  end
15
16
 
@@ -22,11 +23,17 @@ module TheCastleClient
22
23
  end
23
24
 
24
25
  # these are just niceties around the query method; deprecate?
25
- def account_data(id, opts={}); query(id, 'account', '', opts); end
26
+ def account_data(id, opts={}); query(id, 'account', nil, opts); end
26
27
  def account_aggregates(id); query(id, 'account', 'aggregates'); end
27
- def piece_data(id, opts={}); query(id, 'piece', '', opts); end
28
+ def piece_data(id, opts={}); query(id, 'piece', nil, opts); end
28
29
  def piece_aggregates(id); query(id, 'piece', 'aggregates'); end
29
30
 
31
+ def query(id, model='account', data_type=nil, options={})
32
+ raise "Invalid data type #{data_type}" unless ['aggregates', 'referrers', 'embedders', '', nil].include?(data_type)
33
+ url = ['/api', version, model.pluralize, id, data_type].compact.join("/") + to_query(options)
34
+ get(url, {'Accept'=>'application/json', 'Content-Type'=>'application/json'})
35
+ end
36
+
30
37
  protected
31
38
 
32
39
  [:delete, :get, :head, :post, :put, :request].each do |method|
@@ -1,3 +1,3 @@
1
1
  module TheCastleClient
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ # require 'webmock/test_unit'
3
4
 
4
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -1,48 +1,63 @@
1
1
  require 'helper'
2
+ require 'active_support/all'
2
3
 
3
4
  class TestTheCastleClient < Test::Unit::TestCase
4
5
 
5
6
  def setup
6
- TheCastleClient.key = '9NmQzsWBWs8TyfJswqMmkmjwAH3ItNBIC72KLjQK'
7
- TheCastleClient.secret = '592BSoaCb4FfwqsZ6Ql8WShVZ6HVnecR4Dk9lRfQ'
8
- TheCastleClient.host = "development.prx.org"
9
- TheCastleClient.port = 3000
10
- TheCastleClient.version = 'v1'
7
+ TheCastleClient.key = ENV['CASTLE_KEY']
8
+ TheCastleClient.secret = ENV['CASTLE_SECRET']
9
+ TheCastleClient.host = ENV['CASTLE_HOST'] || 'thecastle.dev'
10
+ TheCastleClient.port = ENV['CASTLE_PORT'] || 80
11
+ TheCastleClient.version = ENV['CASTLE_VERSION'] || 'v1'
12
+
13
+ @end_on = Date.today
14
+ @start_on = @end_on - 3.months
15
+
16
+ @account_id = 3437
17
+ @piece_id = 73865
11
18
  end
12
-
19
+
13
20
  def test_account_data
14
- response = TheCastleClient.account_data(7018, {:scale=>'week', :start_on=>'2010-01-01', :end_on=>'2010-04-01'})
21
+ response = TheCastleClient.account_data(@account_id, {:scale=>'week', :start_on=>@start_on, :end_on=>@end_on})
15
22
  puts response.read_body
16
23
  end
17
24
 
18
25
  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'})
26
+ response = TheCastleClient.query(@account_id, 'account', 'embedders', {:scale=>'week', :start_on=>@start_on, :end_on=>@end_on})
25
27
  puts response.read_body
26
28
  end
27
-
29
+
28
30
  def test_account_aggregates
29
- response = TheCastleClient.account_aggregates(7018)
31
+ response = TheCastleClient.account_aggregates(@account_id)
30
32
  puts response.read_body
31
33
  end
32
34
 
33
35
  def test_piece_aggregates
34
- response = TheCastleClient.piece_aggregates(37745)
36
+ response = TheCastleClient.piece_aggregates(@piece_id)
35
37
  puts response.read_body
36
38
  end
37
39
 
38
40
  def test_piece_data
39
- response = TheCastleClient.piece_data(37745, {:scale=>'week', :start_on=>'2010-01-01', :end_on=>'2010-04-01'})
41
+ @end_on = Date.today
42
+ @start_on = @end_on - 3.months
43
+ response = TheCastleClient.piece_data(@piece_id, {:scale=>'week', :start_on=>@start_on, :end_on=>@end_on})
40
44
  puts response.read_body
41
45
  end
42
46
 
43
47
  def test_popular_pieces
44
- response = TheCastleClient.popular_pieces(Date.parse('2011-01-03'), 10)
48
+ response = TheCastleClient.popular_pieces(@start_on, 10)
45
49
  puts response.read_body
46
50
  end
47
51
 
52
+ def test_most_listened_pieces
53
+ response = TheCastleClient.most_listened_pieces(@start_on, 10)
54
+ puts response.read_body
55
+ end
56
+
57
+ # this cube is not deployed to production yet
58
+ # def test_account_referrers
59
+ # response = TheCastleClient.query(128129, 'account', 'referrers', {:scale=>'week', :start_on=>'2011-10-24', :end_on=>'2011-11-02'})
60
+ # puts response.read_body
61
+ # end
62
+
48
63
  end
@@ -1,24 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "the_castle_client/version"
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = "the_castle_client"
7
8
  s.version = TheCastleClient::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["kookster"]
9
+ s.authors = ["Andrew Kuklewicz"]
10
10
  s.email = ["andrew@prx.org"]
11
- s.homepage = ""
12
- s.summary = %q{Get data from the castle, the PRX data warehouse.}
13
11
  s.description = %q{Client to connect via 2-legged oauth, and get data from the castle.}
12
+ s.summary = %q{Get data from the castle, the PRX data warehouse.}
13
+ s.homepage = "https://github.com/PRX/TheCastle"
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ['lib']
14
20
 
15
- s.rubyforge_project = "the_castle_client"
21
+ s.add_development_dependency('bundler')
22
+ s.add_development_dependency('rake')
23
+ # s.add_development_dependency('webmock')
16
24
 
17
- s.add_dependency("activesupport")
18
- s.add_dependency("oauth")
25
+ s.add_runtime_dependency("activesupport")
26
+ s.add_runtime_dependency("oauth")
27
+ s.add_runtime_dependency("json")
19
28
 
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
- s.require_paths = ["lib"]
24
29
  end
metadata CHANGED
@@ -1,61 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: the_castle_client
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
11
5
  platform: ruby
12
- authors:
13
- - kookster
6
+ authors:
7
+ - Andrew Kuklewicz
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-12-01 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: activesupport
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
23
35
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
33
48
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
36
56
  name: oauth
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
37
63
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
47
76
  type: :runtime
48
- version_requirements: *id002
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
49
83
  description: Client to connect via 2-legged oauth, and get data from the castle.
50
- email:
84
+ email:
51
85
  - andrew@prx.org
52
86
  executables: []
53
-
54
87
  extensions: []
55
-
56
88
  extra_rdoc_files: []
57
-
58
- files:
89
+ files:
59
90
  - .gitignore
60
91
  - Gemfile
61
92
  - README.md
@@ -65,40 +96,30 @@ files:
65
96
  - test/helper.rb
66
97
  - test/test_the_castle_client.rb
67
98
  - the_castle_client.gemspec
68
- has_rdoc: true
69
- homepage: ""
70
- licenses: []
71
-
99
+ homepage: https://github.com/PRX/TheCastle
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
72
103
  post_install_message:
73
104
  rdoc_options: []
74
-
75
- require_paths:
105
+ require_paths:
76
106
  - lib
77
- required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
- version: "0"
86
- required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
95
117
  requirements: []
96
-
97
- rubyforge_project: the_castle_client
98
- rubygems_version: 1.4.2
118
+ rubyforge_project:
119
+ rubygems_version: 2.1.11
99
120
  signing_key:
100
- specification_version: 3
121
+ specification_version: 4
101
122
  summary: Get data from the castle, the PRX data warehouse.
102
- test_files:
123
+ test_files:
103
124
  - test/helper.rb
104
125
  - test/test_the_castle_client.rb