greengoose 0.0.1.pre1 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ # - jruby-19mode
5
+ - rbx-19mode
6
+ - ruby-head
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # GreenGoose
2
2
 
3
- Ruby wrapper for the [GreenGoose](http://www.greengoose.com) [API](http://apiwiki.greengoose.com/index.php/REST_API).
3
+ [![Build Status](https://secure.travis-ci.org/alindeman/greengoose.png)](http://travis-ci.org/alindeman/greengoose)
4
4
 
5
- **WIP:** This gem is still a work in progress. It's not fully functional
6
- yet.
5
+ Ruby wrapper for the [GreenGoose](http://www.greengoose.com)
6
+ [API](http://apiwiki.greengoose.com/index.php/REST_API).
7
+
8
+ ## Requirements
9
+
10
+ * MRI 1.9 (or JRuby/rubinius in 1.9 mode)
7
11
 
8
12
  ## Quick Start
9
13
 
@@ -14,9 +18,22 @@ gem 'greengoose'
14
18
  ```
15
19
 
16
20
  Create a client object and authenticate with a username and password
17
- ([signup](http://www.greengoose.com/signup))
21
+ ([signup](http://www.greengoose.com/signup)).
18
22
 
19
23
  ```ruby
20
24
  client = Greengoose::Client.new
21
25
  client.authenticate "username", "password"
22
26
  ```
27
+
28
+ Actions:
29
+
30
+ ```ruby
31
+ client.actions.where(sensor_id: "00000130")
32
+ client.actions.where(sensor_id: "00000130", since_id: "2007240")
33
+ client.actions.where(sensor_id: "00000130", since_id: "2007240", limit: 5)
34
+
35
+ client.actions.where(basestation_id: "0050c2af10ff0000")
36
+
37
+ # http://apiwiki.greengoose.com/index.php/Sensor_Types
38
+ client.actions.where(basestation_id: "0050c2af10ff0000", sensor_type: :bike_snsr)
39
+ ```
data/greengoose.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "pry"
24
24
  s.add_development_dependency "rake"
25
25
 
26
- s.add_runtime_dependency "faraday", "~>0.7"
27
- s.add_runtime_dependency "multi_json", "~>1.0"
26
+ s.add_runtime_dependency "faraday", "~>0.8"
27
+ s.add_runtime_dependency "multi_json", "~>1.3"
28
28
  end
@@ -0,0 +1,9 @@
1
+ require "delegate"
2
+
3
+ module GreenGoose
4
+ class Action < SimpleDelegator
5
+ def initialize(attributes)
6
+ super OpenStruct.new(attributes)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "action"
2
+ require_relative "api"
3
+
4
+ module GreenGoose
5
+ class ActionCollection
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::Action
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module GreenGoose
2
+ module API
3
+ include Enumerable
4
+
5
+ def each
6
+ client.get("actions", conditions).body.each do |result|
7
+ yield klass.new(result)
8
+ end
9
+ end
10
+
11
+ def where(conditions)
12
+ self.class.new(client, conditions.merge(self.conditions))
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,5 @@
1
+ require_relative "action_collection"
2
+
1
3
  module GreenGoose
2
4
  # Green Goose API client
3
5
  class Client
@@ -26,6 +28,10 @@ module GreenGoose
26
28
  self
27
29
  end
28
30
 
31
+ def actions
32
+ GreenGoose::ActionCollection.new(self)
33
+ end
34
+
29
35
  private
30
36
 
31
37
  def connection
@@ -7,7 +7,7 @@ module GreenGoose
7
7
 
8
8
  def call(env)
9
9
  match_content_type(env) do |data|
10
- env[:body] = ::MultiJson.encode(data)
10
+ env[:body] = ::MultiJson.dump(data)
11
11
  end
12
12
 
13
13
  @app.call(env).on_complete do
@@ -24,7 +24,7 @@ module GreenGoose
24
24
  when 'false'
25
25
  false
26
26
  else
27
- ::MultiJson.decode(body)
27
+ ::MultiJson.load(body)
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module GreenGoose
2
- VERSION = "0.0.1.pre1"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe GreenGoose::ActionCollection do
4
+ let(:client) { stub_everything("Client") }
5
+ subject { described_class.new(client) }
6
+
7
+ it "queries the actions API" do
8
+ client.stubs(:get).
9
+ with("actions", {}).
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("actions", 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("actions", 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/action"
3
+
4
+ describe GreenGoose::Action do
5
+ it "is initialized with a hash" do
6
+ action = described_class.new(id: "abc123")
7
+ action.id.should == "abc123"
8
+ end
9
+ end
@@ -22,4 +22,15 @@ describe GreenGoose::Client do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe "#actions" do
27
+ it "builds an action collection with this client" do
28
+ client = described_class.new
29
+
30
+ action_collection = stub_everything
31
+ GreenGoose::ActionCollection.stubs(:new).with(client).returns(action_collection)
32
+
33
+ client.actions.should be(action_collection)
34
+ end
35
+ end
25
36
  end
@@ -10,12 +10,12 @@ describe GreenGoose::Middleware::JSON do
10
10
 
11
11
  describe "request" do
12
12
  it "sends the content type as application/json" do
13
- req = stub_request(:post, "api.greengoose.com").with do |req|
14
- req.headers["Content-Type"] == "application/json"
13
+ req = stub_request(:post, "api.greengoose.com").with do |r|
14
+ r.headers["Content-Type"] == "application/json"
15
15
  end
16
16
 
17
- res = connection.post "/" do |req|
18
- req.body = { }
17
+ res = connection.post "/" do |r|
18
+ r.body = { }
19
19
  end
20
20
 
21
21
  req.should have_been_requested
@@ -25,8 +25,8 @@ describe GreenGoose::Middleware::JSON do
25
25
  req = stub_request(:post, "api.greengoose.com").
26
26
  with(:body => "{\"foo\":\"bar\"}")
27
27
 
28
- res = connection.post "/" do |req|
29
- req.body = { :foo => "bar" }
28
+ res = connection.post "/" do |r|
29
+ r.body = { :foo => "bar" }
30
30
  end
31
31
 
32
32
  req.should have_been_requested
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greengoose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre1
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andy Lindeman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-31 00:00:00.000000000 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70322071249240 !ruby/object:Gem::Requirement
16
+ requirement: &70180210443320 !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: *70322071249240
24
+ version_requirements: *70180210443320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70322071208960 !ruby/object:Gem::Requirement
27
+ requirement: &70180210667480 !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: *70322071208960
35
+ version_requirements: *70180210667480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: webmock
38
- requirement: &70322071208400 !ruby/object:Gem::Requirement
38
+ requirement: &70180210666520 !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: *70322071208400
46
+ version_requirements: *70180210666520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &70322071207600 !ruby/object:Gem::Requirement
49
+ requirement: &70180210665780 !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: *70322071207600
57
+ version_requirements: *70180210665780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &70322071206760 !ruby/object:Gem::Requirement
60
+ requirement: &70180210664280 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,29 +65,29 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70322071206760
68
+ version_requirements: *70180210664280
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday
71
- requirement: &70322071205600 !ruby/object:Gem::Requirement
71
+ requirement: &70180210663300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: '0.7'
76
+ version: '0.8'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70322071205600
79
+ version_requirements: *70180210663300
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: multi_json
82
- requirement: &70322071204560 !ruby/object:Gem::Requirement
82
+ requirement: &70180210662300 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
86
86
  - !ruby/object:Gem::Version
87
- version: '1.0'
87
+ version: '1.3'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70322071204560
90
+ version_requirements: *70180210662300
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:
@@ -97,17 +97,23 @@ extensions: []
97
97
  extra_rdoc_files: []
98
98
  files:
99
99
  - .gitignore
100
+ - .travis.yml
100
101
  - Gemfile
101
102
  - README.md
102
103
  - Rakefile
103
104
  - greengoose.gemspec
104
105
  - lib/greengoose.rb
106
+ - lib/greengoose/action.rb
107
+ - lib/greengoose/action_collection.rb
108
+ - lib/greengoose/api.rb
105
109
  - lib/greengoose/client.rb
106
110
  - lib/greengoose/credentials.rb
107
111
  - lib/greengoose/credentials/basic.rb
108
112
  - lib/greengoose/middleware.rb
109
113
  - lib/greengoose/middleware/json.rb
110
114
  - lib/greengoose/version.rb
115
+ - spec/greengoose/action_collection_spec.rb
116
+ - spec/greengoose/action_spec.rb
111
117
  - spec/greengoose/client_spec.rb
112
118
  - spec/greengoose/credentials/basic_spec.rb
113
119
  - spec/greengoose/middleware/json_spec.rb
@@ -126,20 +132,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
132
  version: '0'
127
133
  segments:
128
134
  - 0
129
- hash: -1129379011405296523
135
+ hash: -1912532368068739857
130
136
  required_rubygems_version: !ruby/object:Gem::Requirement
131
137
  none: false
132
138
  requirements:
133
- - - ! '>'
139
+ - - ! '>='
134
140
  - !ruby/object:Gem::Version
135
- version: 1.3.1
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: -1912532368068739857
136
145
  requirements: []
137
146
  rubyforge_project:
138
- rubygems_version: 1.8.10
147
+ rubygems_version: 1.8.15
139
148
  signing_key:
140
149
  specification_version: 3
141
150
  summary: Provides a Ruby interface to the GreenGoose REST API
142
151
  test_files:
152
+ - spec/greengoose/action_collection_spec.rb
153
+ - spec/greengoose/action_spec.rb
143
154
  - spec/greengoose/client_spec.rb
144
155
  - spec/greengoose/credentials/basic_spec.rb
145
156
  - spec/greengoose/middleware/json_spec.rb