math-api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,9 @@
1
1
  require 'httparty'
2
- require 'pp'
3
2
 
4
3
  module Math
5
4
  class API
6
5
 
7
- VERSION = "0.0.3"
6
+ VERSION = "0.0.4"
8
7
 
9
8
  include HTTParty
10
9
  format :json
@@ -14,7 +13,7 @@ module Math
14
13
 
15
14
  def initialize ( opts = { } )
16
15
 
17
- self.class.base_uri opts[:math_url] || 'http://mathematics.io'
16
+ self.class.base_uri opts[:math_url] || 'https://mathematics.io'
18
17
  self.accesskey = opts[:accesskey]
19
18
  self.user_id = opts[:user_id]
20
19
 
@@ -32,18 +31,31 @@ module Math
32
31
  end
33
32
 
34
33
 
35
- def create_records (data)
34
+ def create_records data
36
35
 
37
36
  raise ArgumentError, "Must specify an item_name" if data[:item_name].nil?
38
37
  raise ArgumentError, "Must specify an amount" if data[:amount].nil?
39
38
 
40
-
41
39
  data = data.merge({ accesskey: @accesskey })
42
40
 
43
41
  self.class.post("/api/1/users/#{@user_id.to_s}/records.json", body: data )
44
42
 
45
43
  end
46
44
 
45
+
46
+ def get_records args
47
+
48
+ raise ArgumentError if args[:item_id].nil?
49
+
50
+ options = { }
51
+ item_id = args[:item_id]
52
+ options[:page] = args[:page] unless args[:page].nil?
53
+ options[:per_page] = args[:per_page] unless args[:per_page].nil?
54
+
55
+ self.class.get("/api/1/users/#{@user_id.to_s}/items/#{item_id.to_s}/records.json", query: options )
56
+
57
+ end
58
+
47
59
  end
48
60
 
49
61
  class API::Error < ::StandardError; end
@@ -12,6 +12,9 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{ API wrapper for Mathematics.io }
13
13
  gem.homepage = "http://github.com/neiltron/math-api"
14
14
 
15
+ gem.add_dependency 'multi_json', '1.7.8'
16
+ gem.add_dependency 'httparty'
17
+
15
18
  gem.files = `git ls-files`.split($/)
16
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -0,0 +1 @@
1
+ {"values":[[1374537600,0],[1374624000,72.0],[1374710400,32.0],[1374796800,96.0],[1374883200,64.0],[1374969600,32.0],[1375056000,0],[1375142400,80.0],[1375228800,16.0],[1375315200,0],[1375401600,48.0],[1375488000,104.0],[1375574400,0],[1375660800,36.0],[1375747200,28.0],[1375833600,0],[1375920000,24.0],[1376006400,44.0],[1376092800,48.0],[1376179200,36.0],[1376265600,48.0],[1376352000,16.0],[1376438400,80.0],[1376524800,32.0],[1376611200,44.0],[1376697600,108.0],[1376784000,32.0],[1376870400,58.0],[1376956800,56.0],[1377043200,64.0],[1377129600,80.0],[1377216000,60.0],[1377302400,0]]}
@@ -0,0 +1 @@
1
+ {"values":[[1374537600,0],[1374624000,72.0],[1374710400,32.0],[1374796800,96.0],[1374883200,64.0],[1374969600,32.0],[1375056000,0],[1375142400,80.0],[1375228800,16.0],[1375315200,0],[1375401600,48.0],[1375488000,104.0],[1375574400,0],[1375660800,36.0],[1375747200,28.0],[1375833600,0],[1375920000,24.0],[1376006400,44.0],[1376092800,48.0],[1376179200,36.0],[1376265600,48.0],[1376352000,16.0],[1376438400,80.0],[1376524800,32.0],[1376611200,44.0],[1376697600,108.0],[1376784000,32.0],[1376870400,58.0],[1376956800,56.0],[1377043200,64.0],[1377129600,80.0],[1377216000,60.0],[1377302400,0]]}
@@ -0,0 +1 @@
1
+ {"values":[[1374537600,0],[1374624000,72.0],[1374710400,32.0],[1374796800,96.0],[1374883200,64.0],[1374969600,32.0],[1375056000,0],[1375142400,80.0],[1375228800,16.0],[1375315200,0]]}
@@ -64,4 +64,48 @@ describe Math::API do
64
64
  end
65
65
 
66
66
  end
67
+
68
+
69
+ describe "get_records" do
70
+
71
+ before(:all) do
72
+ FakeWeb.clean_registry
73
+
74
+ FakeWeb.register_uri(:get, "#{API_ROOT}/api/1/users/profile.json?accesskey=#{ACCESSKEY}", :status => ["200"])
75
+ FakeWeb.register_uri(:get, "#{API_ROOT}/api/1/users/#{USER_ID}/items/totallyrealitemid/records.json", :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "records_page1.json")), :content_type => 'application/json')
76
+ FakeWeb.register_uri(:get, "#{API_ROOT}/api/1/users/#{USER_ID}/items/totallyrealitemid/records.json?page=2", :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "records_page2.json")), :content_type => 'application/json')
77
+ FakeWeb.register_uri(:get, "#{API_ROOT}/api/1/users/#{USER_ID}/items/totallyrealitemid/records.json?per_page=10", :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "records_perpage.json")), :content_type => 'application/json')
78
+
79
+ @api = Math::API.new( accesskey: ACCESSKEY, user_id: USER_ID, math_url: API_ROOT )
80
+ end
81
+
82
+ it "returns an argumenterror if no item_id is specified" do
83
+
84
+ expect{ @api.get_records }.to raise_error(ArgumentError)
85
+
86
+ end
87
+
88
+ it "returns a set of records" do
89
+
90
+ @page1 = @api.get_records({ item_id: 'totallyrealitemid' })
91
+ @page1.values[0].count.should == 33
92
+
93
+ end
94
+
95
+ it "returns a different set of records" do
96
+
97
+ @page2 = @api.get_records({ item_id: 'totallyrealitemid', page: 2 })
98
+ @page2.values[0].should_not == @page1
99
+
100
+ end
101
+
102
+ it "returns a different amount of records using per_page" do
103
+
104
+ records = @api.get_records({ item_id: 'totallyrealitemid', per_page: 10 })
105
+ records.values[0].count.should == 10
106
+
107
+ end
108
+
109
+ end
110
+
67
111
  end
@@ -1,4 +1,6 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
- require 'math-api'
3
2
 
3
+ require 'math-api'
4
4
  require 'fakeweb'
5
+
6
+ FakeWeb.allow_net_connect = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: math-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-18 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: &70333937898340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.7.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70333937898340
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ requirement: &70333937897900 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70333937897900
14
36
  description: ! ' API wrapper for Mathematics.io '
15
37
  email:
16
38
  - neil@descend.org
@@ -25,6 +47,9 @@ files:
25
47
  - Rakefile
26
48
  - lib/math-api.rb
27
49
  - math-api.gemspec
50
+ - spec/fixtures/records_page1.json
51
+ - spec/fixtures/records_page2.json
52
+ - spec/fixtures/records_perpage.json
28
53
  - spec/mathapi_spec.rb
29
54
  - spec/spec.opts
30
55
  - spec/spec_helper.rb
@@ -53,6 +78,9 @@ signing_key:
53
78
  specification_version: 3
54
79
  summary: API wrapper for Mathematics.io
55
80
  test_files:
81
+ - spec/fixtures/records_page1.json
82
+ - spec/fixtures/records_page2.json
83
+ - spec/fixtures/records_perpage.json
56
84
  - spec/mathapi_spec.rb
57
85
  - spec/spec.opts
58
86
  - spec/spec_helper.rb