machineshop 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.
- checksums.yaml +7 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/compiler.xml +23 -0
- data/.idea/copyright/profiles_settings.xml +5 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +7 -0
- data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
- data/.idea/machineshop.iml +194 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +722 -0
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/doc.txt +50 -0
- data/lib/machineshop.rb +234 -0
- data/lib/machineshop/api_operations/create.rb +17 -0
- data/lib/machineshop/api_operations/delete.rb +11 -0
- data/lib/machineshop/api_operations/list.rb +16 -0
- data/lib/machineshop/api_operations/update.rb +17 -0
- data/lib/machineshop/api_resource.rb +35 -0
- data/lib/machineshop/configuration.rb +11 -0
- data/lib/machineshop/customer.rb +9 -0
- data/lib/machineshop/database.rb +112 -0
- data/lib/machineshop/device.rb +30 -0
- data/lib/machineshop/device_instance.rb +30 -0
- data/lib/machineshop/errors/api_error.rb +4 -0
- data/lib/machineshop/errors/authentication_error.rb +4 -0
- data/lib/machineshop/errors/database_error.rb +5 -0
- data/lib/machineshop/errors/invalid_request_error.rb +10 -0
- data/lib/machineshop/errors/machineshop_error.rb +20 -0
- data/lib/machineshop/json.rb +21 -0
- data/lib/machineshop/machineshop_cache.rb +49 -0
- data/lib/machineshop/machineshop_object.rb +164 -0
- data/lib/machineshop/mapping.rb +34 -0
- data/lib/machineshop/meter.rb +12 -0
- data/lib/machineshop/models/people.rb +11 -0
- data/lib/machineshop/report.rb +11 -0
- data/lib/machineshop/rule.rb +58 -0
- data/lib/machineshop/user.rb +43 -0
- data/lib/machineshop/util.rb +115 -0
- data/lib/machineshop/utility.rb +30 -0
- data/lib/machineshop/version.rb +3 -0
- data/machineshop.gemspec +24 -0
- data/spec/lib/api_calls_spec.rb +628 -0
- data/spec/lib/customer_spec.rb +76 -0
- data/spec/lib/device_spec.rb +179 -0
- data/spec/lib/mapping_spec.rb +64 -0
- data/spec/lib/meter_spec.rb +46 -0
- data/spec/lib/report_spec.rb +52 -0
- data/spec/lib/rule_spec.rb +117 -0
- data/spec/lib/user_spec.rb +53 -0
- data/spec/spec_helper.rb +3 -0
- metadata +184 -0
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 5 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 8 | 
            +
            publisher_username = 'publisher@csr.com'
         | 
| 9 | 
            +
            publisher_password = 'password'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
             | 
| 12 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 13 | 
            +
                  :email => publisher_username,
         | 
| 14 | 
            +
                  :password => publisher_password
         | 
| 15 | 
            +
              )
         | 
| 16 | 
            +
            describe MachineShop::Customer do
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              it "should get all the customers " do
         | 
| 19 | 
            +
                customers = MachineShop::Customer.all({}, auth_token)
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                puts "customers are #{customers}"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                #puts "first customer is : #{customers[0][:id]}"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                customers.should_not be_nil
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
               specificCustomer = nil
         | 
| 29 | 
            +
              it "should create customer " do
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                specificCustomer = MachineShop::Customer.create({:email=>"bajratests@bajratechnologies.com",
         | 
| 32 | 
            +
                                                         :password=>'password',
         | 
| 33 | 
            +
                                                         :notification_method=>'sms',
         | 
| 34 | 
            +
                                                         :first_name=>'niroj',:last_name=>'sapkota',
         | 
| 35 | 
            +
                                                         :phone_number=>'98989898989',
         | 
| 36 | 
            +
                                                         :company_name=>'technology co'
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                                                        },auth_token)
         | 
| 39 | 
            +
                puts "created customer is #{specificCustomer}"
         | 
| 40 | 
            +
                specificCustomer.should_not be_nil
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
             | 
| 44 | 
            +
             
         | 
| 45 | 
            +
              it "should get customer by customer id " do
         | 
| 46 | 
            +
                ap "looking up customer before:"
         | 
| 47 | 
            +
                ap specificCustomer.as_json
         | 
| 48 | 
            +
                
         | 
| 49 | 
            +
                specificCustomer = MachineShop::Customer.retrieve(specificCustomer.id, auth_token)
         | 
| 50 | 
            +
                
         | 
| 51 | 
            +
                ap "looking up customer after:"
         | 
| 52 | 
            +
                ap specificCustomer.as_json
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                specificCustomer.should_not be_nil
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              it "should update the customer with id " do
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                puts "updating customer with id : #{specificCustomer.id}"
         | 
| 60 | 
            +
                update = MachineShop::Customer.update(specificCustomer.id,auth_token,{:notification_method => 'email'})
         | 
| 61 | 
            +
                puts "update #{update}"
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              
         | 
| 64 | 
            +
              #success test
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              it "should delete customer with id " do
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                #puts
         | 
| 69 | 
            +
                puts "deleting customer with id : #{specificCustomer.id}"
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                delete = specificCustomer.delete
         | 
| 72 | 
            +
                #delete = MachineShop::Customer.delete(customers[0].id,auth_token)
         | 
| 73 | 
            +
                puts "delete #{delete}"
         | 
| 74 | 
            +
                delete.http_code.should eq 200
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
| @@ -0,0 +1,179 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 4 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 7 | 
            +
            publisher_username = 'admin@csr.com'
         | 
| 8 | 
            +
            publisher_password = 'password'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 12 | 
            +
                  :email => publisher_username,
         | 
| 13 | 
            +
                  :password => publisher_password
         | 
| 14 | 
            +
              )
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            describe MachineShop::Device do
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              device = nil
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              it "should get all devices for the user" do
         | 
| 21 | 
            +
                element_data = MachineShop::Device.all(
         | 
| 22 | 
            +
                    {:page => 1,
         | 
| 23 | 
            +
                     :per_page => 10},
         | 
| 24 | 
            +
                    auth_token)
         | 
| 25 | 
            +
                device = element_data[0]
         | 
| 26 | 
            +
                device.should_not be_nil
         | 
| 27 | 
            +
                device.should be_kind_of MachineShop::Device
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            specificDevice = nil
         | 
| 31 | 
            +
             | 
| 32 | 
            +
             | 
| 33 | 
            +
              it "should get a device for the user by id" do
         | 
| 34 | 
            +
                specificDevice = MachineShop::Device.retrieve(device.id, auth_token)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                ap "Device by id"
         | 
| 37 | 
            +
                ap specificDevice.as_json
         | 
| 38 | 
            +
                specificDevice.should_not be_nil
         | 
| 39 | 
            +
                specificDevice.should be_kind_of MachineShop::Device
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
             | 
| 43 | 
            +
             | 
| 44 | 
            +
              it "should delete device" do
         | 
| 45 | 
            +
                delete = specificDevice.delete
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                ap "Delete Device by id"
         | 
| 48 | 
            +
                ap delete.as_json
         | 
| 49 | 
            +
                delete.http_code.should eq 200
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
             | 
| 53 | 
            +
              it "should get a device for the user by name" do
         | 
| 54 | 
            +
                element_data = MachineShop::Device.all(
         | 
| 55 | 
            +
                    {
         | 
| 56 | 
            +
                        :name => device.name
         | 
| 57 | 
            +
                    },
         | 
| 58 | 
            +
                    auth_token)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                element_data.should_not be_nil
         | 
| 61 | 
            +
                element_data.should_not be_empty
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
             | 
| 65 | 
            +
              device = nil
         | 
| 66 | 
            +
             | 
| 67 | 
            +
              it "should get all devices for the user" do
         | 
| 68 | 
            +
                element_data = MachineShop::Device.all(
         | 
| 69 | 
            +
                    {:page => 1,
         | 
| 70 | 
            +
                     :per_page => 10},
         | 
| 71 | 
            +
                    auth_token)
         | 
| 72 | 
            +
                device = element_data[0]
         | 
| 73 | 
            +
                device.should_not be_nil
         | 
| 74 | 
            +
                device.should be_kind_of MachineShop::Device
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              it "should get a device for the user by name" do
         | 
| 78 | 
            +
                element_data = MachineShop::Device.all(
         | 
| 79 | 
            +
                    {
         | 
| 80 | 
            +
                        :name => device.name
         | 
| 81 | 
            +
                    },
         | 
| 82 | 
            +
                    auth_token)
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                element_data.should_not be_nil
         | 
| 85 | 
            +
                element_data.should_not be_empty
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
            describe MachineShop::DeviceInstance do
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              device = nil
         | 
| 93 | 
            +
              device_instance = nil
         | 
| 94 | 
            +
             | 
| 95 | 
            +
              it "should create a device instance for the user" do
         | 
| 96 | 
            +
                # First create a device to use
         | 
| 97 | 
            +
                device = MachineShop::Device.create(
         | 
| 98 | 
            +
                    {
         | 
| 99 | 
            +
                        :name =>  "my_device",
         | 
| 100 | 
            +
                        :type => "Test",
         | 
| 101 | 
            +
                        :manufacturer =>  "a company",
         | 
| 102 | 
            +
                        :model =>  "D-vice 1000",
         | 
| 103 | 
            +
                        :active =>  "yes",
         | 
| 104 | 
            +
                        :init_cmd =>  "my_init_cmd",
         | 
| 105 | 
            +
                        :init_params =>  "{'init':'go'}",
         | 
| 106 | 
            +
                        :exe_path =>  "/etc/foo",
         | 
| 107 | 
            +
                        :unit_price =>  "$199.99",
         | 
| 108 | 
            +
                        :sample_data =>  "some arbitrary sample data",
         | 
| 109 | 
            +
                        :long_description =>  "This device tracks position and NCAA football conference.",
         | 
| 110 | 
            +
                        :image_url =>  "http://someurl.com/your_image.png",
         | 
| 111 | 
            +
                        :manual_url =>  "http://someurl.com/manual.pdf"
         | 
| 112 | 
            +
                    },
         | 
| 113 | 
            +
                    auth_token)
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                ap "device created:"
         | 
| 116 | 
            +
                ap device.as_json
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                # Now create an instance
         | 
| 119 | 
            +
                device_instance = device.create_instance(
         | 
| 120 | 
            +
                    {
         | 
| 121 | 
            +
                        :name => "My little instance",
         | 
| 122 | 
            +
                        :active => "yes"
         | 
| 123 | 
            +
                    }
         | 
| 124 | 
            +
                )
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                device_instance.should_not be_nil
         | 
| 127 | 
            +
                device_instance.should be_kind_of MachineShop::DeviceInstance
         | 
| 128 | 
            +
              end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
             | 
| 131 | 
            +
              it "should get device instances" do
         | 
| 132 | 
            +
                element_data = MachineShop::DeviceInstance.all({}, auth_token)
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                device_instance = element_data[0]
         | 
| 135 | 
            +
                element_data.should_not be_nil
         | 
| 136 | 
            +
                element_data.should_not be_empty
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                device_instance.should be_kind_of MachineShop::DeviceInstance
         | 
| 139 | 
            +
              end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
             | 
| 142 | 
            +
              it "should get a device instance by id" do
         | 
| 143 | 
            +
                element_data = MachineShop::DeviceInstance.retrieve(device_instance.id, auth_token)
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                ap "Device Instance by id: "
         | 
| 146 | 
            +
                ap element_data.as_json
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                element_data.should_not be_nil
         | 
| 149 | 
            +
                element_data.should be_kind_of MachineShop::DeviceInstance
         | 
| 150 | 
            +
              end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
              it "should get a device instance by name" do
         | 
| 153 | 
            +
                element_data = MachineShop::DeviceInstance.all({:name => device_instance.name}, auth_token)
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                ap "Device Instance by name: "
         | 
| 156 | 
            +
                ap element_data.as_json
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                element_data.should_not be_nil
         | 
| 159 | 
            +
                element_data.should_not be_empty
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              it "should get all devices via a user" do
         | 
| 163 | 
            +
                element_data = user.device_instances
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                ap "Device Instance via user "
         | 
| 166 | 
            +
                ap element_data.as_json
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                element_data.should_not be_nil
         | 
| 169 | 
            +
                element_data.should_not be_empty
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
              it "should get all devices via a user with a filter" do
         | 
| 173 | 
            +
                element_data = user.device_instances({:name => device_instance.name})
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                element_data.should_not be_nil
         | 
| 176 | 
            +
                element_data.should_not be_empty
         | 
| 177 | 
            +
              end
         | 
| 178 | 
            +
             | 
| 179 | 
            +
            end
         | 
| @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 4 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 7 | 
            +
            publisher_username = 'publisher@csr.com'
         | 
| 8 | 
            +
            publisher_password = 'password'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 12 | 
            +
                  :email => publisher_username,
         | 
| 13 | 
            +
                  :password => publisher_password
         | 
| 14 | 
            +
              )
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            describe MachineShop::Mapping do
         | 
| 17 | 
            +
             | 
| 18 | 
            +
               it "should get a geocoded address" do
         | 
| 19 | 
            +
                element_data = MachineShop::Mapping.geocode(
         | 
| 20 | 
            +
                    {
         | 
| 21 | 
            +
                        :address => "1600 Amphitheatre Parkway, Mountain View, CA",
         | 
| 22 | 
            +
                        :sensor => "false"
         | 
| 23 | 
            +
                    },
         | 
| 24 | 
            +
                    auth_token)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                #puts "GEO: #{element_data}"
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                element_data.should_not be_nil
         | 
| 29 | 
            +
                element_data.should_not be_empty
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              it "should get directions" do
         | 
| 33 | 
            +
                element_data = MachineShop::Mapping.directions(
         | 
| 34 | 
            +
                    {
         | 
| 35 | 
            +
                        :origin => "Denver",
         | 
| 36 | 
            +
                        :destination => "Boston",
         | 
| 37 | 
            +
                        :sensor => "false"
         | 
| 38 | 
            +
                    },
         | 
| 39 | 
            +
                    auth_token)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                #puts "GEO: #{element_data}"
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                element_data.should_not be_nil
         | 
| 44 | 
            +
                element_data.should_not be_empty
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              it "should get distance" do
         | 
| 48 | 
            +
                element_data = MachineShop::Mapping.distance(
         | 
| 49 | 
            +
                    {
         | 
| 50 | 
            +
                        :origins => "Vancouver BC",
         | 
| 51 | 
            +
                        :destinations => "San Francisco",
         | 
| 52 | 
            +
                        :mode => "bicycling",
         | 
| 53 | 
            +
                        :language => "fr-FR",
         | 
| 54 | 
            +
                        :sensor => "false"
         | 
| 55 | 
            +
                    },
         | 
| 56 | 
            +
                    auth_token)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                #puts "GEO: #{element_data}"
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                element_data.should_not be_nil
         | 
| 61 | 
            +
                element_data.should_not be_empty
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            end
         | 
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 4 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 7 | 
            +
            publisher_username = 'publisher@csr.com'
         | 
| 8 | 
            +
            publisher_password = 'password'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 12 | 
            +
                  :email => publisher_username,
         | 
| 13 | 
            +
                  :password => publisher_password
         | 
| 14 | 
            +
              )
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              element_data=nil
         | 
| 17 | 
            +
            describe MachineShop::Meter do
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              it "should get all meter data" do
         | 
| 20 | 
            +
                element_data = MachineShop::Meter.all({}, auth_token)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                # puts "element_data from all: #{element_data}"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                element_data.should_not be_nil
         | 
| 25 | 
            +
                element_data.should_not be_empty
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              it "should get meter by id " do
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                meter_id = element_data[0].id
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                # element_data = MachineShop::Meter.retrieve(meter_id, auth_token)
         | 
| 33 | 
            +
                element_data = MachineShop::Meter.retrieve("53847ac2b99e9c0a30000001", auth_token)
         | 
| 34 | 
            +
                puts "meter by id : #{element_data}"
         | 
| 35 | 
            +
                element_data.should_not be_nil
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              it "should get meters via a user" do
         | 
| 39 | 
            +
                element_data = user.meters
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                # puts "meters via user: #{element_data}"
         | 
| 42 | 
            +
                element_data.should_not be_nil
         | 
| 43 | 
            +
                element_data.should_not be_empty
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            end
         | 
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 4 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 7 | 
            +
            publisher_username = 'publisher@csr.com'
         | 
| 8 | 
            +
            publisher_password = 'password'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 12 | 
            +
                  :email => publisher_username,
         | 
| 13 | 
            +
                  :password => publisher_password
         | 
| 14 | 
            +
              )
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              reports=nil
         | 
| 17 | 
            +
            describe MachineShop::Report do
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                it "should get all report data" do
         | 
| 20 | 
            +
                element_data = MachineShop::Report.all({}, auth_token)
         | 
| 21 | 
            +
            reports=element_data
         | 
| 22 | 
            +
                # puts "element_data: #{element_data}"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                element_data.should_not be_nil
         | 
| 25 | 
            +
                element_data.should_not be_empty
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
| 30 | 
            +
              it "should get report of specific device" do
         | 
| 31 | 
            +
                element_data = MachineShop::Report.all(
         | 
| 32 | 
            +
                    ({:device_instance_id => '538461dc9818006e0900005e',
         | 
| 33 | 
            +
                      :per_page=>'1000',
         | 
| 34 | 
            +
                      #:created_at_between=>'2013-11-04T00:00:00_2014-03-19T17:02:00'
         | 
| 35 | 
            +
                    }), auth_token)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                puts "element data of f00e5981800ad58000006 #{element_data} "
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                element_data.should_not be_nil
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              it "should get specific report by id" do
         | 
| 43 | 
            +
                specific_report_id=reports[0].id
         | 
| 44 | 
            +
                element_data = MachineShop::Report.retrieve("5384800dff7346390c000001",auth_token)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                puts "report specific #{element_data} "
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                element_data.should_not be_nil
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
             | 
| 52 | 
            +
            end
         | 
| @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            require_relative '../spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
         | 
| 4 | 
            +
            MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            #publisher_username = 'publisher@machineshop.com'
         | 
| 7 | 
            +
            publisher_username = 'publisher@csr.com'
         | 
| 8 | 
            +
            publisher_password = 'password'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
             | 
| 11 | 
            +
              auth_token, user = MachineShop::User.authenticate(
         | 
| 12 | 
            +
                  :email => publisher_username,
         | 
| 13 | 
            +
                  :password => publisher_password
         | 
| 14 | 
            +
              )
         | 
| 15 | 
            +
             | 
| 16 | 
            +
             | 
| 17 | 
            +
            describe MachineShop::Rule do
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              rules=nil
         | 
| 20 | 
            +
             
         | 
| 21 | 
            +
              it "should get all the rules " do
         | 
| 22 | 
            +
                rules = MachineShop::Rule.all({},auth_token)
         | 
| 23 | 
            +
                # puts "rules haru : #{rules}"
         | 
| 24 | 
            +
                rules.should_not be_nil
         | 
| 25 | 
            +
             | 
| 26 | 
            +
             | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
| 30 | 
            +
             | 
| 31 | 
            +
             
         | 
| 32 | 
            +
              it "should create rule" do
         | 
| 33 | 
            +
             | 
| 34 | 
            +
             | 
| 35 | 
            +
             create_hash = {
         | 
| 36 | 
            +
                  :devices=>["52585e1d981800bab2000479"],
         | 
| 37 | 
            +
                  :device_instances=>[],
         | 
| 38 | 
            +
                  :rule=>{
         | 
| 39 | 
            +
                      :active=>true,
         | 
| 40 | 
            +
                      :description=>"bajratest",
         | 
| 41 | 
            +
                      :condition=>{
         | 
| 42 | 
            +
                          :type=>"and_rule_condition",
         | 
| 43 | 
            +
                          :rule_conditions=>[{
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                              :property=>"var",
         | 
| 46 | 
            +
                              :value=>"30",
         | 
| 47 | 
            +
                              :type=>"equal_rule_condition"
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                          }]
         | 
| 50 | 
            +
                      },
         | 
| 51 | 
            +
                      :then_actions=>[{
         | 
| 52 | 
            +
                          :priority=>"1",
         | 
| 53 | 
            +
                          :send_to=>"abc@me.com",
         | 
| 54 | 
            +
                          :type=>"email_rule_action"
         | 
| 55 | 
            +
                      }]
         | 
| 56 | 
            +
                  }
         | 
| 57 | 
            +
              }
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                createdRule = MachineShop::Rule.create(create_hash,auth_token)
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                createdRule.should_not be_nil
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              specificRule = nil
         | 
| 66 | 
            +
             
         | 
| 67 | 
            +
              it "should get rule by id" do
         | 
| 68 | 
            +
                # ruleById = MachineShop::Rule.retrieve(rules[0].id,auth_token)
         | 
| 69 | 
            +
                specificRule = MachineShop::Rule.retrieve("53857b5e385f7fd509000019",auth_token)
         | 
| 70 | 
            +
                ap "retrieved rule"
         | 
| 71 | 
            +
                ap specificRule.as_json
         | 
| 72 | 
            +
                specificRule.should_not be_nil
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              it "should delete rule by" do
         | 
| 77 | 
            +
                # ruleById = MachineShop::Rule.retrieve(rules[0].id,auth_token)
         | 
| 78 | 
            +
                delete = specificRule.delete
         | 
| 79 | 
            +
                ap "Deleted rule"
         | 
| 80 | 
            +
                ap delete.as_json
         | 
| 81 | 
            +
                delete.should_not be_nil
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              it "should get get join rule conditions" do
         | 
| 86 | 
            +
                test_data = MachineShop::Rule.get_join_rule_conditions(auth_token)
         | 
| 87 | 
            +
                puts "rule comparison : #{test_data.inspect}"
         | 
| 88 | 
            +
                test_data.should_not be_nil
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
             | 
| 93 | 
            +
              it "should get comparison rule_conditions" do
         | 
| 94 | 
            +
                test_data = MachineShop::Rule.get_comparison_rule_conditions(auth_token)
         | 
| 95 | 
            +
                ap "comparison rule condition  :"
         | 
| 96 | 
            +
                ap test_data.as_json
         | 
| 97 | 
            +
                test_data.should_not be_nil
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
             | 
| 102 | 
            +
              it "should get rule by device_id" do
         | 
| 103 | 
            +
                test_data = MachineShop::Rule.get_by_device_instance(auth_token,'52585e1d981800bab2000478')
         | 
| 104 | 
            +
                ap "rule by_device_instance :"
         | 
| 105 | 
            +
                ap test_data.as_json
         | 
| 106 | 
            +
                test_data.should_not be_nil
         | 
| 107 | 
            +
             | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              it "should get deleted rule" do
         | 
| 111 | 
            +
                test_data = MachineShop::Rule.get_deleted(auth_token)
         | 
| 112 | 
            +
                puts "deleted rule : #{test_data.inspect}"
         | 
| 113 | 
            +
                test_data.should_not be_nil
         | 
| 114 | 
            +
             | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
             
         | 
| 117 | 
            +
            end
         |