greengoose 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,7 +21,7 @@ Create a client object and authenticate with a username and password
21
21
  ([signup](http://www.greengoose.com/signup)).
22
22
 
23
23
  ```ruby
24
- client = Greengoose::Client.new
24
+ client = GreenGoose::Client.new
25
25
  client.authenticate "username", "password"
26
26
  ```
27
27
 
@@ -1,4 +1,5 @@
1
1
  require "delegate"
2
+ require "ostruct"
2
3
 
3
4
  module GreenGoose
4
5
  class Action < SimpleDelegator
@@ -15,5 +15,9 @@ module GreenGoose
15
15
  def klass
16
16
  GreenGoose::Action
17
17
  end
18
+
19
+ def endpoint
20
+ "actions"
21
+ end
18
22
  end
19
23
  end
@@ -3,7 +3,7 @@ module GreenGoose
3
3
  include Enumerable
4
4
 
5
5
  def each
6
- client.get("actions", conditions).body.each do |result|
6
+ client.get(endpoint, conditions).body.each do |result|
7
7
  yield klass.new(result)
8
8
  end
9
9
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "action_collection"
2
+ require_relative "stat_collection"
2
3
 
3
4
  module GreenGoose
4
5
  # Green Goose API client
@@ -32,6 +33,10 @@ module GreenGoose
32
33
  GreenGoose::ActionCollection.new(self)
33
34
  end
34
35
 
36
+ def stats
37
+ GreenGoose::StatCollection.new(self)
38
+ end
39
+
35
40
  private
36
41
 
37
42
  def connection
@@ -0,0 +1,10 @@
1
+ require "delegate"
2
+ require "ostruct"
3
+
4
+ module GreenGoose
5
+ class Stat < SimpleDelegator
6
+ def initialize(attributes)
7
+ super OpenStruct.new(attributes)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ require_relative "stat"
2
+ require_relative "api"
3
+
4
+ module GreenGoose
5
+ class StatCollection
6
+ include API
7
+
8
+ attr_reader :client, :conditions
9
+
10
+ def initialize(client, conditions = {})
11
+ @client = client
12
+ @conditions = conditions
13
+ end
14
+
15
+ def klass
16
+ GreenGoose::Stat
17
+ end
18
+
19
+ def endpoint
20
+ "stats"
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module GreenGoose
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe GreenGoose::StatCollection do
4
+ let(:client) { stub_everything("Client") }
5
+ subject { described_class.new(client) }
6
+
7
+ it "queries the stats API" do
8
+ client.stubs(:get).
9
+ with("stats", {}).
10
+ returns(stub(body: [{id: "123abc"}, {id: "987zyx"}]))
11
+
12
+ subject.to_a.map(&:id).should == ["123abc", "987zyx"]
13
+ end
14
+
15
+ describe "#where" do
16
+ it "scopes down the search" do
17
+ scoped_to_sensor = subject.where(sensor_id: "abc123")
18
+
19
+ client.stubs(:get).
20
+ with("stats", sensor_id: "abc123").
21
+ returns(stub(body: [{id: "123abc"}]))
22
+
23
+ scoped_to_sensor.to_a.map(&:id).should == ["123abc"]
24
+ end
25
+
26
+ it "supports chaining" do
27
+ scoped_to_sensor_and_limit = subject.where(sensor_id: "abc123").
28
+ where(limit: 5)
29
+
30
+
31
+ client.stubs(:get).
32
+ with("stats", sensor_id: "abc123", limit: 5).
33
+ returns(stub(body: [{id: "123abc"}]))
34
+
35
+ scoped_to_sensor_and_limit.to_a.map(&:id).should == ["123abc"]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+ require_relative "../../lib/greengoose/stat"
3
+
4
+ describe GreenGoose::Stat do
5
+ it "is initialized with a hash" do
6
+ stat = described_class.new(id: "abc123")
7
+ stat.id.should == "abc123"
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greengoose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70180210443320 !ruby/object:Gem::Requirement
16
+ requirement: &70109114232300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.7.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70180210443320
24
+ version_requirements: *70109114232300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70180210667480 !ruby/object:Gem::Requirement
27
+ requirement: &70109114231680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.10.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70180210667480
35
+ version_requirements: *70109114231680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: webmock
38
- requirement: &70180210666520 !ruby/object:Gem::Requirement
38
+ requirement: &70109114231200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.7.8
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70180210666520
46
+ version_requirements: *70109114231200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70180210665780 !ruby/object:Gem::Requirement
49
+ requirement: &70109114230820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70180210665780
57
+ version_requirements: *70109114230820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70180210664280 !ruby/object:Gem::Requirement
60
+ requirement: &70109114230300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70180210664280
68
+ version_requirements: *70109114230300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday
71
- requirement: &70180210663300 !ruby/object:Gem::Requirement
71
+ requirement: &70109114229760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.8'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70180210663300
79
+ version_requirements: *70109114229760
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: multi_json
82
- requirement: &70180210662300 !ruby/object:Gem::Requirement
82
+ requirement: &70109114229120 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '1.3'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70180210662300
90
+ version_requirements: *70109114229120
91
91
  description: ! "The GreenGoose API enables developers to build fun applications that
92
92
  interact with the GreenGoose real-world sensor platform\n "
93
93
  email:
@@ -111,12 +111,16 @@ files:
111
111
  - lib/greengoose/credentials/basic.rb
112
112
  - lib/greengoose/middleware.rb
113
113
  - lib/greengoose/middleware/json.rb
114
+ - lib/greengoose/stat.rb
115
+ - lib/greengoose/stat_collection.rb
114
116
  - lib/greengoose/version.rb
115
117
  - spec/greengoose/action_collection_spec.rb
116
118
  - spec/greengoose/action_spec.rb
117
119
  - spec/greengoose/client_spec.rb
118
120
  - spec/greengoose/credentials/basic_spec.rb
119
121
  - spec/greengoose/middleware/json_spec.rb
122
+ - spec/greengoose/stat_collection_spec.rb
123
+ - spec/greengoose/stat_spec.rb
120
124
  - spec/spec_helper.rb
121
125
  homepage: https://github.com/alindeman/greengoose
122
126
  licenses: []
@@ -132,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
136
  version: '0'
133
137
  segments:
134
138
  - 0
135
- hash: -1912532368068739857
139
+ hash: -4382726329904586798
136
140
  required_rubygems_version: !ruby/object:Gem::Requirement
137
141
  none: false
138
142
  requirements:
@@ -141,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
145
  version: '0'
142
146
  segments:
143
147
  - 0
144
- hash: -1912532368068739857
148
+ hash: -4382726329904586798
145
149
  requirements: []
146
150
  rubyforge_project:
147
151
  rubygems_version: 1.8.15
@@ -154,4 +158,6 @@ test_files:
154
158
  - spec/greengoose/client_spec.rb
155
159
  - spec/greengoose/credentials/basic_spec.rb
156
160
  - spec/greengoose/middleware/json_spec.rb
161
+ - spec/greengoose/stat_collection_spec.rb
162
+ - spec/greengoose/stat_spec.rb
157
163
  - spec/spec_helper.rb