greengoose 0.0.1.pre1 → 0.0.1
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.
- data/.travis.yml +6 -0
- data/README.md +21 -4
- data/greengoose.gemspec +2 -2
- data/lib/greengoose/action.rb +9 -0
- data/lib/greengoose/action_collection.rb +19 -0
- data/lib/greengoose/api.rb +15 -0
- data/lib/greengoose/client.rb +6 -0
- data/lib/greengoose/middleware/json.rb +2 -2
- data/lib/greengoose/version.rb +1 -1
- data/spec/greengoose/action_collection_spec.rb +38 -0
- data/spec/greengoose/action_spec.rb +9 -0
- data/spec/greengoose/client_spec.rb +11 -0
- data/spec/greengoose/middleware/json_spec.rb +6 -6
- metadata +34 -23
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,9 +1,13 @@ | |
| 1 1 | 
             
            # GreenGoose
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            [](http://travis-ci.org/alindeman/greengoose)
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 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. | 
| 27 | 
            -
              s.add_runtime_dependency "multi_json", "~>1. | 
| 26 | 
            +
              s.add_runtime_dependency "faraday", "~>0.8"
         | 
| 27 | 
            +
              s.add_runtime_dependency "multi_json", "~>1.3"
         | 
| 28 28 | 
             
            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
         | 
    
        data/lib/greengoose/client.rb
    CHANGED
    
    | @@ -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. | 
| 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. | 
| 27 | 
            +
                      ::MultiJson.load(body)
         | 
| 28 28 | 
             
                    end
         | 
| 29 29 | 
             
                  end
         | 
| 30 30 | 
             
                end
         | 
    
        data/lib/greengoose/version.rb
    CHANGED
    
    
| @@ -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
         | 
| @@ -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 | | 
| 14 | 
            -
                     | 
| 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 | | 
| 18 | 
            -
                     | 
| 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 | | 
| 29 | 
            -
                     | 
| 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 | 
| 5 | 
            -
              prerelease:  | 
| 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:  | 
| 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: & | 
| 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: * | 
| 24 | 
            +
              version_requirements: *70180210443320
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: mocha
         | 
| 27 | 
            -
              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: * | 
| 35 | 
            +
              version_requirements: *70180210667480
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: webmock
         | 
| 38 | 
            -
              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: * | 
| 46 | 
            +
              version_requirements: *70180210666520
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: pry
         | 
| 49 | 
            -
              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: * | 
| 57 | 
            +
              version_requirements: *70180210665780
         | 
| 58 58 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 59 59 | 
             
              name: rake
         | 
| 60 | 
            -
              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: * | 
| 68 | 
            +
              version_requirements: *70180210664280
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: faraday
         | 
| 71 | 
            -
              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. | 
| 76 | 
            +
                    version: '0.8'
         | 
| 77 77 | 
             
              type: :runtime
         | 
| 78 78 | 
             
              prerelease: false
         | 
| 79 | 
            -
              version_requirements: * | 
| 79 | 
            +
              version_requirements: *70180210663300
         | 
| 80 80 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 81 81 | 
             
              name: multi_json
         | 
| 82 | 
            -
              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. | 
| 87 | 
            +
                    version: '1.3'
         | 
| 88 88 | 
             
              type: :runtime
         | 
| 89 89 | 
             
              prerelease: false
         | 
| 90 | 
            -
              version_requirements: * | 
| 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: - | 
| 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:  | 
| 141 | 
            +
                  version: '0'
         | 
| 142 | 
            +
                  segments:
         | 
| 143 | 
            +
                  - 0
         | 
| 144 | 
            +
                  hash: -1912532368068739857
         | 
| 136 145 | 
             
            requirements: []
         | 
| 137 146 | 
             
            rubyforge_project: 
         | 
| 138 | 
            -
            rubygems_version: 1.8. | 
| 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
         |