cs 0.1.0beta3 → 0.1.0
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.
- checksums.yaml +7 -0
 - data/.travis.yml +8 -0
 - data/Gemfile +22 -6
 - data/README.md +15 -4
 - data/cs.gemspec +7 -7
 - data/lib/{commonsense-ruby-lib.rb → cs.rb} +80 -31
 - data/lib/{commonsense-ruby-lib → cs}/auth/http.rb +52 -33
 - data/lib/{commonsense-ruby-lib → cs}/auth/oauth.rb +28 -28
 - data/lib/cs/collection.rb +7 -0
 - data/lib/cs/collection/sensor_data_collection.rb +61 -0
 - data/lib/{commonsense-ruby-lib → cs}/end_point.rb +36 -24
 - data/lib/cs/end_point/group.rb +26 -0
 - data/lib/cs/end_point/notification.rb +16 -0
 - data/lib/{commonsense-ruby-lib → cs}/end_point/sensor.rb +22 -6
 - data/lib/{commonsense-ruby-lib → cs}/end_point/sensor_data.rb +17 -6
 - data/lib/cs/end_point/trigger.rb +16 -0
 - data/lib/{commonsense-ruby-lib → cs}/end_point/user.rb +8 -4
 - data/lib/{commonsense-ruby-lib → cs}/error.rb +7 -1
 - data/lib/cs/parameter_processor.rb +99 -0
 - data/lib/cs/relation.rb +244 -0
 - data/lib/cs/relation/group_relation.rb +24 -0
 - data/lib/cs/relation/notification_relation.rb +20 -0
 - data/lib/{commonsense-ruby-lib → cs}/relation/sensor_data_relation.rb +7 -52
 - data/lib/{commonsense-ruby-lib → cs}/relation/sensor_relation.rb +28 -55
 - data/lib/cs/relation/trigger_relation.rb +21 -0
 - data/lib/cs/relation/user_relation.rb +20 -0
 - data/lib/{commonsense-ruby-lib → cs}/serializer.rb +1 -1
 - data/lib/cs/session.rb +170 -0
 - data/lib/cs/time.rb +45 -0
 - data/lib/cs/version.rb +3 -0
 - data/spec/features/sensor_management_spec.rb +146 -45
 - data/spec/features/user_management_spec.rb +94 -22
 - data/spec/lib/cs/collection/sensor_data_collection_spec.rb +27 -0
 - data/spec/lib/cs/end_point/group_spec.rb +120 -0
 - data/spec/lib/cs/end_point/sensor_data_spec.rb +110 -0
 - data/spec/lib/{commonsense-ruby-lib → cs}/end_point/sensor_spec.rb +6 -6
 - data/spec/lib/{commonsense-ruby-lib → cs}/end_point/user_spec.rb +14 -7
 - data/spec/lib/{commonsense-ruby-lib → cs}/end_point_spec.rb +25 -12
 - data/spec/lib/cs/relation/group_relation_spec.rb +103 -0
 - data/spec/lib/cs/relation/sensor_data_relation_spec.rb +184 -0
 - data/spec/lib/cs/relation/sensor_relation_spec.rb +192 -0
 - data/spec/lib/cs/relation/user_relation_spec.rb +81 -0
 - data/spec/lib/cs/relation_spec.rb +151 -0
 - data/spec/lib/cs/session_spec.rb +91 -0
 - data/spec/lib/cs/time_spec.rb +71 -0
 - data/spec/lib/cs_spec.rb +85 -0
 - data/spec/spec_helper.rb +6 -26
 - metadata +69 -86
 - data/lib/commonsense-ruby-lib/end_point/group.rb +0 -28
 - data/lib/commonsense-ruby-lib/relation.rb +0 -233
 - data/lib/commonsense-ruby-lib/session.rb +0 -105
 - data/lib/commonsense-ruby-lib/version.rb +0 -3
 - data/spec/lib/commonsense-ruby-lib/end_point/sensor_data_spec.rb +0 -68
 - data/spec/lib/commonsense-ruby-lib/relation/sensor_data_relation_spec.rb +0 -444
 - data/spec/lib/commonsense-ruby-lib/relation/sensor_relation_spec.rb +0 -165
 - data/spec/lib/commonsense-ruby-lib/session_spec.rb +0 -43
 - data/spec/lib/commonsense-ruby-lib_spec.rb +0 -51
 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CS
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Collection
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe SensorDataCollection do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  describe "process_batch" do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    it "should convert into multi data payload" do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      sdc = SensorDataCollection.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                      sdc.batch_size = 2
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                      current_batch = [
         
     | 
| 
      
 12 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 1, value: 1),
         
     | 
| 
      
 13 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 1, value: 2),
         
     | 
| 
      
 14 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 2, value: 1),
         
     | 
| 
      
 15 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 2, value: 2),
         
     | 
| 
      
 16 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 1, value: 3),
         
     | 
| 
      
 17 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 1, value: 4),
         
     | 
| 
      
 18 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 2, value: 3),
         
     | 
| 
      
 19 
     | 
    
         
            +
                        EndPoint::SensorData.new(sensor_id: 2, value: 4)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                      sdc.process_batch(current_batch)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,120 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CS
         
     | 
| 
      
 4 
     | 
    
         
            +
              module EndPoint
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe Sensor do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  let(:group_info) do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    {
         
     | 
| 
      
 9 
     | 
    
         
            +
                      name: "group1",
         
     | 
| 
      
 10 
     | 
    
         
            +
                      anonymous: false,
         
     | 
| 
      
 11 
     | 
    
         
            +
                      public: true,
         
     | 
| 
      
 12 
     | 
    
         
            +
                      hidden: false,
         
     | 
| 
      
 13 
     | 
    
         
            +
                      description: "Description of group1",
         
     | 
| 
      
 14 
     | 
    
         
            +
                      required_sensors: ["Location", "position"],
         
     | 
| 
      
 15 
     | 
    
         
            +
                      default_list_users: true,
         
     | 
| 
      
 16 
     | 
    
         
            +
                      default_add_users: true,
         
     | 
| 
      
 17 
     | 
    
         
            +
                      default_remove_users: true,
         
     | 
| 
      
 18 
     | 
    
         
            +
                      default_list_sensors: true,
         
     | 
| 
      
 19 
     | 
    
         
            +
                      default_add_sensors: true,
         
     | 
| 
      
 20 
     | 
    
         
            +
                      required_show_id: true,
         
     | 
| 
      
 21 
     | 
    
         
            +
                      required_show_email: true,
         
     | 
| 
      
 22 
     | 
    
         
            +
                      required_show_first_name: true,
         
     | 
| 
      
 23 
     | 
    
         
            +
                      required_show_surname: true,
         
     | 
| 
      
 24 
     | 
    
         
            +
                      required_show_phone_number: true,
         
     | 
| 
      
 25 
     | 
    
         
            +
                      required_show_username: true
         
     | 
| 
      
 26 
     | 
    
         
            +
                    }
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  describe "Initiating new sensor" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    it "should assign the group property on initialize" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                      info = group_info
         
     | 
| 
      
 32 
     | 
    
         
            +
                      info[:id] = 1
         
     | 
| 
      
 33 
     | 
    
         
            +
                      group = Group.new(info)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      group.id.should eq(1)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      group.name.should eq("group1")
         
     | 
| 
      
 36 
     | 
    
         
            +
                      group.anonymous.should be_false
         
     | 
| 
      
 37 
     | 
    
         
            +
                      group.public.should be_true
         
     | 
| 
      
 38 
     | 
    
         
            +
                      group.hidden.should be_false
         
     | 
| 
      
 39 
     | 
    
         
            +
                      group.description.should eq("Description of group1")
         
     | 
| 
      
 40 
     | 
    
         
            +
                      group.required_sensors.should eq(["Location", "position"])
         
     | 
| 
      
 41 
     | 
    
         
            +
                      group.default_list_users.should be_true
         
     | 
| 
      
 42 
     | 
    
         
            +
                      group.default_add_users.should be_true
         
     | 
| 
      
 43 
     | 
    
         
            +
                      group.default_remove_users.should be_true
         
     | 
| 
      
 44 
     | 
    
         
            +
                      group.default_list_sensors.should be_true
         
     | 
| 
      
 45 
     | 
    
         
            +
                      group.default_add_sensors.should be_true
         
     | 
| 
      
 46 
     | 
    
         
            +
                      group.required_show_id.should be_true
         
     | 
| 
      
 47 
     | 
    
         
            +
                      group.required_show_email.should be_true
         
     | 
| 
      
 48 
     | 
    
         
            +
                      group.required_show_first_name.should be_true
         
     | 
| 
      
 49 
     | 
    
         
            +
                      group.required_show_surname.should be_true
         
     | 
| 
      
 50 
     | 
    
         
            +
                      group.required_show_phone_number.should be_true
         
     | 
| 
      
 51 
     | 
    
         
            +
                      group.required_show_username.should be_true
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  describe "Creating" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    it "should POST to /groups.json" do
         
     | 
| 
      
 57 
     | 
    
         
            +
                      group = Group.new(group_info)
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 60 
     | 
    
         
            +
                      expected = {"group" => group_info }
         
     | 
| 
      
 61 
     | 
    
         
            +
                      session.should_receive(:post).with("/groups.json", expected)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      session.stub(:response_headers => {"location" => "http://foo.bar/groups/1"})
         
     | 
| 
      
 63 
     | 
    
         
            +
                      session.stub(:response_code => 201)
         
     | 
| 
      
 64 
     | 
    
         
            +
                      group.session = session
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                      group.save!.should be_true
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  describe "Get specific data point" do
         
     | 
| 
      
 71 
     | 
    
         
            +
                    it "should request GET to /groups/:id.json" do
         
     | 
| 
      
 72 
     | 
    
         
            +
                      group = Group.new(group_info)
         
     | 
| 
      
 73 
     | 
    
         
            +
                      group_id = 1
         
     | 
| 
      
 74 
     | 
    
         
            +
                      group.id = group_id
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 77 
     | 
    
         
            +
                      session.should_receive(:get).with("/groups/#{group_id}.json")
         
     | 
| 
      
 78 
     | 
    
         
            +
                      session.stub(:response_code => 200)
         
     | 
| 
      
 79 
     | 
    
         
            +
                      group.session = session
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                      group.retrieve!.should be_true
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  describe "Update specific group point" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                    it "should request data point from commonSense" do
         
     | 
| 
      
 87 
     | 
    
         
            +
                      group = Group.new(group_info)
         
     | 
| 
      
 88 
     | 
    
         
            +
                      group_id = 1
         
     | 
| 
      
 89 
     | 
    
         
            +
                      group.id = group_id
         
     | 
| 
      
 90 
     | 
    
         
            +
                      group.name = "group 1 edit"
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 93 
     | 
    
         
            +
                      expected = {"group" => group_info }
         
     | 
| 
      
 94 
     | 
    
         
            +
                      expected["group"][:name] = "group 1 edit"
         
     | 
| 
      
 95 
     | 
    
         
            +
                      expected["group"][:id] = 1
         
     | 
| 
      
 96 
     | 
    
         
            +
                      session.should_receive(:put).with("/groups/#{group_id}.json", expected)
         
     | 
| 
      
 97 
     | 
    
         
            +
                      session.stub(:response_code => 200)
         
     | 
| 
      
 98 
     | 
    
         
            +
                      group.session = session
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                      group.save!.should be_true
         
     | 
| 
      
 101 
     | 
    
         
            +
                    end
         
     | 
| 
      
 102 
     | 
    
         
            +
                  end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  describe "Delete specific data point" do
         
     | 
| 
      
 105 
     | 
    
         
            +
                    it "should perform DELETE request to commonSense" do
         
     | 
| 
      
 106 
     | 
    
         
            +
                      group = Group.new(group_info)
         
     | 
| 
      
 107 
     | 
    
         
            +
                      group_id = 1
         
     | 
| 
      
 108 
     | 
    
         
            +
                      group.id = group_id
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 111 
     | 
    
         
            +
                      session.should_receive(:delete).with("/groups/#{group_id}.json")
         
     | 
| 
      
 112 
     | 
    
         
            +
                      session.stub(:response_code => 200)
         
     | 
| 
      
 113 
     | 
    
         
            +
                      group.session = session
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                      group.delete!.should be_true
         
     | 
| 
      
 116 
     | 
    
         
            +
                    end
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
              end
         
     | 
| 
      
 120 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,110 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module CS
         
     | 
| 
      
 4 
     | 
    
         
            +
              module EndPoint
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe SensorData do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  let!(:value) do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    {"x-axis" => 1.0, "y-axis" => 2.0, "z-axis" => 3.0}
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  let!(:now) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                    Time.now
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  context "Initiating new data point" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    it "should assign the data point property on initialize" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      data = SensorData.new(sensor_id: 1, date: now, value: value)
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      data.sensor_id.should eq(1)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      data.date.to_i.should eq(now.to_i)
         
     | 
| 
      
 21 
     | 
    
         
            +
                      data.value.should eq(value)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  describe "to_parameters" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    context "given CS::Time object" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                      it "should convert date to epoch" do
         
     | 
| 
      
 28 
     | 
    
         
            +
                        data = SensorData.new(id: 1)
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                        date = Time.now
         
     | 
| 
      
 31 
     | 
    
         
            +
                        epoch = date.to_f
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                        data.date = date
         
     | 
| 
      
 34 
     | 
    
         
            +
                        data.to_parameters[:data][0][:date].should be_within(0.001).of(epoch)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                    context "given TimeLord object" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                      it "should convert date to epoch" do
         
     | 
| 
      
 40 
     | 
    
         
            +
                        require 'time-lord'
         
     | 
| 
      
 41 
     | 
    
         
            +
                        data = SensorData.new(id: 1)
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                        date = 1.hours.ago
         
     | 
| 
      
 44 
     | 
    
         
            +
                        epoch = Time.new(date).to_f
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                        data.date = date
         
     | 
| 
      
 47 
     | 
    
         
            +
                        data.to_parameters[:data][0][:date].should be_within(0.001).of(epoch)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                    context "given method respond to_time" do
         
     | 
| 
      
 52 
     | 
    
         
            +
                      it "should convert date to epoch" do
         
     | 
| 
      
 53 
     | 
    
         
            +
                        data = SensorData.new(id: 1)
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                        date = Time.now
         
     | 
| 
      
 56 
     | 
    
         
            +
                        epoch = date.to_f
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                        double = double()
         
     | 
| 
      
 59 
     | 
    
         
            +
                        double.should_receive(:to_time).and_return(date)
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                        data.date = double
         
     | 
| 
      
 62 
     | 
    
         
            +
                        data.to_parameters[:data][0][:date].should be_within(0.001).of(epoch)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      end
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  context "Creating" do
         
     | 
| 
      
 68 
     | 
    
         
            +
                    it "should create a new data point" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                      date_value = Time.now
         
     | 
| 
      
 70 
     | 
    
         
            +
                      data = SensorData.new(sensor_id: 1, date: date_value, value: value)
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 73 
     | 
    
         
            +
                      session.should_receive(:post).with("/sensors/1/data.json", {data: [{date: date_value.to_f.round(3), value: value.to_json}]})
         
     | 
| 
      
 74 
     | 
    
         
            +
                      session.stub(:response_headers => {"location" => "http://foo.bar/sensors/1/data/1"})
         
     | 
| 
      
 75 
     | 
    
         
            +
                      session.stub(:response_code => 201)
         
     | 
| 
      
 76 
     | 
    
         
            +
                      data.session = session
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                      data.create!.should be_true
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
                  end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                  context "Get specific data point" do
         
     | 
| 
      
 83 
     | 
    
         
            +
                    it "should request data point from commonSense" do
         
     | 
| 
      
 84 
     | 
    
         
            +
                      data = SensorData.new
         
     | 
| 
      
 85 
     | 
    
         
            +
                      expect { data.retrieve!.should }.to raise_error(Error::NotImplementedError)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  context "Update specific data point" do
         
     | 
| 
      
 90 
     | 
    
         
            +
                    it "should request data point from commonSense" do
         
     | 
| 
      
 91 
     | 
    
         
            +
                      data = SensorData.new
         
     | 
| 
      
 92 
     | 
    
         
            +
                      expect { data.retrieve!.should }.to raise_error(Error::NotImplementedError)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    end
         
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  context "Delete specific data point" do
         
     | 
| 
      
 97 
     | 
    
         
            +
                    it "should perform DELETE request to commonSense" do
         
     | 
| 
      
 98 
     | 
    
         
            +
                      data = SensorData.new(sensor_id: 1, id: "abcdef")
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
      
 101 
     | 
    
         
            +
                      session.should_receive(:delete).with("/sensors/1/data/abcdef.json")
         
     | 
| 
      
 102 
     | 
    
         
            +
                      session.stub(:response_code => 200)
         
     | 
| 
      
 103 
     | 
    
         
            +
                      data.session = session
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                      data.delete!.should be_true
         
     | 
| 
      
 106 
     | 
    
         
            +
                    end
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,8 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            module  
     | 
| 
      
 3 
     | 
    
         
            +
            module CS
         
     | 
| 
       4 
4 
     | 
    
         
             
              module EndPoint
         
     | 
| 
       5 
     | 
    
         
            -
                describe  
     | 
| 
      
 5 
     | 
    
         
            +
                describe Sensor do
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
                  let(:sensor_info) do
         
     | 
| 
       8 
8 
     | 
    
         
             
                    {
         
     | 
| 
         @@ -34,7 +34,7 @@ module CommonSense 
     | 
|
| 
       34 
34 
     | 
    
         
             
                    it "should POST to /sensors.json" do
         
     | 
| 
       35 
35 
     | 
    
         
             
                      sensor = Sensor.new(sensor_info)
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 37 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       38 
38 
     | 
    
         
             
                      expected = {sensor: sensor_info }
         
     | 
| 
       39 
39 
     | 
    
         
             
                      expected[:sensor][:data_structure] = (sensor_info[:data_structure].to_json)
         
     | 
| 
       40 
40 
     | 
    
         
             
                      session.should_receive(:post).with("/sensors.json", expected)
         
     | 
| 
         @@ -52,7 +52,7 @@ module CommonSense 
     | 
|
| 
       52 
52 
     | 
    
         
             
                      sensor_id = 1
         
     | 
| 
       53 
53 
     | 
    
         
             
                      sensor.id = sensor_id
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 55 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       56 
56 
     | 
    
         
             
                      session.should_receive(:get).with("/sensors/#{sensor_id}.json")
         
     | 
| 
       57 
57 
     | 
    
         
             
                      session.stub(:response_code => 200)
         
     | 
| 
       58 
58 
     | 
    
         
             
                      sensor.session = session
         
     | 
| 
         @@ -67,7 +67,7 @@ module CommonSense 
     | 
|
| 
       67 
67 
     | 
    
         
             
                      sensor_id = 1
         
     | 
| 
       68 
68 
     | 
    
         
             
                      sensor.id = sensor_id
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 70 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       71 
71 
     | 
    
         
             
                      expected = {sensor: sensor_info }
         
     | 
| 
       72 
72 
     | 
    
         
             
                      expected[:sensor][:data_structure] = (sensor_info[:data_structure].to_json)
         
     | 
| 
       73 
73 
     | 
    
         
             
                      expected[:sensor][:id] = 1
         
     | 
| 
         @@ -85,7 +85,7 @@ module CommonSense 
     | 
|
| 
       85 
85 
     | 
    
         
             
                      sensor_id = 1
         
     | 
| 
       86 
86 
     | 
    
         
             
                      sensor.id = sensor_id
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 88 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       89 
89 
     | 
    
         
             
                      session.should_receive(:delete).with("/sensors/#{sensor_id}.json")
         
     | 
| 
       90 
90 
     | 
    
         
             
                      session.stub(:response_code => 200)
         
     | 
| 
       91 
91 
     | 
    
         
             
                      sensor.session = session
         
     | 
| 
         @@ -1,21 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
            require ' 
     | 
| 
      
 2 
     | 
    
         
            +
            require 'cs/error'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            module  
     | 
| 
      
 4 
     | 
    
         
            +
            module CS
         
     | 
| 
       5 
5 
     | 
    
         
             
              module EndPoint
         
     | 
| 
       6 
6 
     | 
    
         
             
                describe User do
         
     | 
| 
       7 
7 
     | 
    
         
             
                  def valid_user
         
     | 
| 
       8 
8 
     | 
    
         
             
                    {
         
     | 
| 
       9 
9 
     | 
    
         
             
                      id: 1, email: "foo@bar.com", username: "foo@bar.com", name: "foo",
         
     | 
| 
       10 
     | 
    
         
            -
                      surname: "bar", address: "foo", zipcode: "12345", country: " 
     | 
| 
       11 
     | 
    
         
            -
                      mobile: "12345",  
     | 
| 
      
 10 
     | 
    
         
            +
                      surname: "bar", address: "foo", zipcode: "12345", country: "NETHERLANDS",
         
     | 
| 
      
 11 
     | 
    
         
            +
                      mobile: "12345", UUID: "12345", openid: "12345"
         
     | 
| 
       12 
12 
     | 
    
         
             
                    }
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                  describe "current_user" do
         
     | 
| 
       16 
16 
     | 
    
         
             
                    it "should return current logged in user" do
         
     | 
| 
       17 
17 
     | 
    
         
             
                      user = User.new
         
     | 
| 
       18 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 18 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       19 
19 
     | 
    
         
             
                      session.stub(:get).with("/users/current.json").and_return({"user" => valid_user}) 
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                      user.stub(:session).and_return(session);
         
     | 
| 
         @@ -25,10 +25,17 @@ module CommonSense 
     | 
|
| 
       25 
25 
     | 
    
         
             
                    end
         
     | 
| 
       26 
26 
     | 
    
         
             
                  end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
28 
     | 
    
         
             
                  describe "save" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                    context "with id not specified and no session" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                      it "should raise error" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                        user = User.new(valid_user)
         
     | 
| 
      
 32 
     | 
    
         
            +
                        user.id = nil
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                        expect { user.save! }.to raise_error(Error::ClientError, "No session found. use Client#new_user instead")
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
       30 
37 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
      
 38 
     | 
    
         
            +
                    context "with id specified" do
         
     | 
| 
       32 
39 
     | 
    
         
             
                    end
         
     | 
| 
       33 
40 
     | 
    
         
             
                  end
         
     | 
| 
       34 
41 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            module  
     | 
| 
      
 3 
     | 
    
         
            +
            module CS
         
     | 
| 
       4 
4 
     | 
    
         
             
              describe EndPoint do
         
     | 
| 
       5 
5 
     | 
    
         
             
                before(:each) do
         
     | 
| 
       6 
6 
     | 
    
         
             
                  class FooEndPoint
         
     | 
| 
         @@ -40,7 +40,7 @@ module CommonSense 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  describe "without id" do
         
     | 
| 
       41 
41 
     | 
    
         
             
                    it "should call create" do
         
     | 
| 
       42 
42 
     | 
    
         
             
                      foo = FooEndPoint.new
         
     | 
| 
       43 
     | 
    
         
            -
                      foo.session = double(" 
     | 
| 
      
 43 
     | 
    
         
            +
                      foo.session = double("CS::Session")
         
     | 
| 
       44 
44 
     | 
    
         
             
                      foo.should_receive(:create!)
         
     | 
| 
       45 
45 
     | 
    
         
             
                      foo.save!
         
     | 
| 
       46 
46 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -49,7 +49,7 @@ module CommonSense 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  describe "with id" do
         
     | 
| 
       50 
50 
     | 
    
         
             
                    it "should call update" do
         
     | 
| 
       51 
51 
     | 
    
         
             
                      foo = FooEndPoint.new
         
     | 
| 
       52 
     | 
    
         
            -
                      foo.session = double(" 
     | 
| 
      
 52 
     | 
    
         
            +
                      foo.session = double("CS::Session")
         
     | 
| 
       53 
53 
     | 
    
         
             
                      foo.id = 1
         
     | 
| 
       54 
54 
     | 
    
         
             
                      foo.should_receive(:update!)
         
     | 
| 
       55 
55 
     | 
    
         
             
                      foo.save!
         
     | 
| 
         @@ -60,7 +60,7 @@ module CommonSense 
     | 
|
| 
       60 
60 
     | 
    
         
             
                describe "save" do
         
     | 
| 
       61 
61 
     | 
    
         
             
                  it "should not raise error" do
         
     | 
| 
       62 
62 
     | 
    
         
             
                    foo = FooEndPoint.new
         
     | 
| 
       63 
     | 
    
         
            -
                    foo.session = double(" 
     | 
| 
      
 63 
     | 
    
         
            +
                    foo.session = double("CS::Session")
         
     | 
| 
       64 
64 
     | 
    
         
             
                    foo.should_receive(:create!).and_return { raise Error }
         
     | 
| 
       65 
65 
     | 
    
         
             
                    foo.save.should be_false
         
     | 
| 
       66 
66 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -71,7 +71,7 @@ module CommonSense 
     | 
|
| 
       71 
71 
     | 
    
         
             
                    foo_data = valid_foo
         
     | 
| 
       72 
72 
     | 
    
         
             
                    foo_data.delete(:id)
         
     | 
| 
       73 
73 
     | 
    
         
             
                    foo = FooEndPoint.new(foo_data)
         
     | 
| 
       74 
     | 
    
         
            -
                    session = double(" 
     | 
| 
      
 74 
     | 
    
         
            +
                    session = double("CS::Session")
         
     | 
| 
       75 
75 
     | 
    
         
             
                    session.should_receive(:post).with("/foos.json", {foo: foo_data}).and_return({"foo" => valid_foo})
         
     | 
| 
       76 
76 
     | 
    
         
             
                    session.stub(:response_headers => {"location" => "http://foo.bar/foos/1"})
         
     | 
| 
       77 
77 
     | 
    
         
             
                    session.stub(:response_code => 201)
         
     | 
| 
         @@ -84,7 +84,7 @@ module CommonSense 
     | 
|
| 
       84 
84 
     | 
    
         
             
                  it "should raise exception where recive error (not 201) from commonSense" do
         
     | 
| 
       85 
85 
     | 
    
         
             
                    expect {
         
     | 
| 
       86 
86 
     | 
    
         
             
                      foo = FooEndPoint.new
         
     | 
| 
       87 
     | 
    
         
            -
                      session = double(" 
     | 
| 
      
 87 
     | 
    
         
            +
                      session = double("CS::Session")
         
     | 
| 
       88 
88 
     | 
    
         
             
                      session.stub(:post)
         
     | 
| 
       89 
89 
     | 
    
         
             
                      session.stub(response_code: 409)
         
     | 
| 
       90 
90 
     | 
    
         
             
                      session.stub(:errors)
         
     | 
| 
         @@ -106,14 +106,14 @@ module CommonSense 
     | 
|
| 
       106 
106 
     | 
    
         
             
                  it "should raise exception with no id" do
         
     | 
| 
       107 
107 
     | 
    
         
             
                    expect {
         
     | 
| 
       108 
108 
     | 
    
         
             
                      foo = FooEndPoint.new
         
     | 
| 
       109 
     | 
    
         
            -
                      foo.session = double(" 
     | 
| 
      
 109 
     | 
    
         
            +
                      foo.session = double("CS::Session")
         
     | 
| 
       110 
110 
     | 
    
         
             
                      foo.retrieve!
         
     | 
| 
       111 
111 
     | 
    
         
             
                    }.to raise_error(Error::ResourceIdError)
         
     | 
| 
       112 
112 
     | 
    
         
             
                  end
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
                  it "should GET Resource from CommonSense" do
         
     | 
| 
       115 
115 
     | 
    
         
             
                    foo = FooEndPoint.new(id: 1)
         
     | 
| 
       116 
     | 
    
         
            -
                    session = double(" 
     | 
| 
      
 116 
     | 
    
         
            +
                    session = double("CS::Session")
         
     | 
| 
       117 
117 
     | 
    
         
             
                    session.should_receive(:get).with("/foos/1.json").and_return({"foo" => valid_foo})
         
     | 
| 
       118 
118 
     | 
    
         
             
                    session.stub(:response_code => 200)
         
     | 
| 
       119 
119 
     | 
    
         
             
                    foo.session = session
         
     | 
| 
         @@ -138,7 +138,7 @@ module CommonSense 
     | 
|
| 
       138 
138 
     | 
    
         
             
                  it "should PUT Resource to CommonSense" do
         
     | 
| 
       139 
139 
     | 
    
         
             
                    foo_data = valid_foo
         
     | 
| 
       140 
140 
     | 
    
         
             
                    foo = FooEndPoint.new(foo_data)
         
     | 
| 
       141 
     | 
    
         
            -
                    session = double(" 
     | 
| 
      
 141 
     | 
    
         
            +
                    session = double("CS::Session")
         
     | 
| 
       142 
142 
     | 
    
         
             
                    session.should_receive(:put).with("/foos/1.json", {foo: foo_data}).and_return({"foo" => valid_foo})
         
     | 
| 
       143 
143 
     | 
    
         
             
                    session.stub(:response_code => 200)
         
     | 
| 
       144 
144 
     | 
    
         
             
                    foo.session = session
         
     | 
| 
         @@ -159,7 +159,7 @@ module CommonSense 
     | 
|
| 
       159 
159 
     | 
    
         
             
                  it "should raise exception with no id" do
         
     | 
| 
       160 
160 
     | 
    
         
             
                    expect {
         
     | 
| 
       161 
161 
     | 
    
         
             
                      foo = FooEndPoint.new
         
     | 
| 
       162 
     | 
    
         
            -
                      foo.session = double(" 
     | 
| 
      
 162 
     | 
    
         
            +
                      foo.session = double("CS::Session")
         
     | 
| 
       163 
163 
     | 
    
         
             
                      foo.delete!
         
     | 
| 
       164 
164 
     | 
    
         
             
                    }.to raise_error(Error::ResourceIdError)
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
         @@ -167,7 +167,7 @@ module CommonSense 
     | 
|
| 
       167 
167 
     | 
    
         | 
| 
       168 
168 
     | 
    
         
             
                  it "should DELETE Resource from CommonSense" do
         
     | 
| 
       169 
169 
     | 
    
         
             
                    foo = FooEndPoint.new(id: 1)
         
     | 
| 
       170 
     | 
    
         
            -
                    session = double(" 
     | 
| 
      
 170 
     | 
    
         
            +
                    session = double("CS::Session")
         
     | 
| 
       171 
171 
     | 
    
         
             
                    session.should_receive(:delete).with("/foos/1.json")
         
     | 
| 
       172 
172 
     | 
    
         
             
                    session.stub(:response_code => 200)
         
     | 
| 
       173 
173 
     | 
    
         
             
                    foo.session = session
         
     | 
| 
         @@ -181,10 +181,23 @@ module CommonSense 
     | 
|
| 
       181 
181 
     | 
    
         
             
                describe "delete" do
         
     | 
| 
       182 
182 
     | 
    
         
             
                  it "should not raise error" do
         
     | 
| 
       183 
183 
     | 
    
         
             
                    foo = FooEndPoint.new
         
     | 
| 
       184 
     | 
    
         
            -
                    foo.session = double(" 
     | 
| 
      
 184 
     | 
    
         
            +
                    foo.session = double("CS::Session")
         
     | 
| 
       185 
185 
     | 
    
         
             
                    foo.stub(:delete!).and_return { raise Error }
         
     | 
| 
       186 
186 
     | 
    
         
             
                    foo.delete.should be_false
         
     | 
| 
       187 
187 
     | 
    
         
             
                  end
         
     | 
| 
       188 
188 
     | 
    
         
             
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                describe "duplicate" do
         
     | 
| 
      
 191 
     | 
    
         
            +
                  it "should duplicate the endpoint object without id" do
         
     | 
| 
      
 192 
     | 
    
         
            +
                    foo = FooEndPoint.new
         
     | 
| 
      
 193 
     | 
    
         
            +
                    foo.attribute1 = 'attribute1'
         
     | 
| 
      
 194 
     | 
    
         
            +
                    foo.attribute2 = 'attribute2'
         
     | 
| 
      
 195 
     | 
    
         
            +
                    foo.id = 1
         
     | 
| 
      
 196 
     | 
    
         
            +
                    bar = foo.duplicate
         
     | 
| 
      
 197 
     | 
    
         
            +
                    bar.id.should be_nil
         
     | 
| 
      
 198 
     | 
    
         
            +
                    bar.attribute1 = 'attribute1'
         
     | 
| 
      
 199 
     | 
    
         
            +
                    bar.attribute2 = 'attribute2'
         
     | 
| 
      
 200 
     | 
    
         
            +
                  end
         
     | 
| 
      
 201 
     | 
    
         
            +
                end
         
     | 
| 
       189 
202 
     | 
    
         
             
              end
         
     | 
| 
       190 
203 
     | 
    
         
             
            end
         
     |