active_rest_client 0.9.67 → 0.9.68
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 +4 -4
 - data/README.md +8 -1
 - data/lib/active_rest_client/base.rb +19 -0
 - data/lib/active_rest_client/version.rb +1 -1
 - data/spec/lib/base_spec.rb +34 -0
 - data/spec/spec_helper.rb +3 -3
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 165810386481e53bc5f8720c4f655a5a135dea49
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 16f2ccfac3c0fb433d7466ba5c45915da4bdc698
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a52f66dfcc518464a454a151dbfe80921712479a02e3a4724feab9dd7bf75c62de08698725cc9c1c45f6fc5b4bb2a52b605f83acf7750b859c7a9c021dfd581c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e17da1d91c4fdb8c44dbb8bc9b72ceda0d96ca764861a0a25afec8269884ee6b7c20f0b15ed0fcf558d422acf379395c2eaf93dd9c851ccb16a05d0c8e80cbc3
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -102,9 +102,16 @@ puts @tv.properties["3d"] 
     | 
|
| 
       102 
102 
     | 
    
         
             
            @tv.properties["3d"] = true
         
     | 
| 
       103 
103 
     | 
    
         
             
            ```
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
      
 105 
     | 
    
         
            +
            If you want to debug the response, using inspect on the response object may well be useful.  However, if you want a simpler output, then you can call `#to_json` on the response object:
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 108 
     | 
    
         
            +
            @person = Person.find(email:"something@example.com")
         
     | 
| 
      
 109 
     | 
    
         
            +
            puts @person.to_json
         
     | 
| 
      
 110 
     | 
    
         
            +
            ```
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
       105 
112 
     | 
    
         
             
            ## Advanced Features
         
     | 
| 
       106 
113 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
            ### Configuration
         
     | 
| 
      
 114 
     | 
    
         
            +
            ### Faraday Configuration
         
     | 
| 
       108 
115 
     | 
    
         | 
| 
       109 
116 
     | 
    
         
             
            ActiveRestClient uses Faraday to allow switching HTTP backends, the default is Patron. To change the used backend just set it in the class by setting `adapter` to a Faraday supported adapter symbol.
         
     | 
| 
       110 
117 
     | 
    
         | 
| 
         @@ -127,6 +127,25 @@ module ActiveRestClient 
     | 
|
| 
       127 
127 
     | 
    
         
             
                def respond_to_missing?(method_name, include_private = false)
         
     | 
| 
       128 
128 
     | 
    
         
             
                  @attributes.has_key? method_name.to_sym
         
     | 
| 
       129 
129 
     | 
    
         
             
                end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                def to_hash
         
     | 
| 
      
 132 
     | 
    
         
            +
                  output = {}
         
     | 
| 
      
 133 
     | 
    
         
            +
                  @attributes.each do |key, value|
         
     | 
| 
      
 134 
     | 
    
         
            +
                    if value.is_a? ActiveRestClient::Base
         
     | 
| 
      
 135 
     | 
    
         
            +
                      output[key.to_s] = value.to_hash
         
     | 
| 
      
 136 
     | 
    
         
            +
                    elsif value.is_a? Array
         
     | 
| 
      
 137 
     | 
    
         
            +
                      output[key.to_s] = value.map(&:to_hash)
         
     | 
| 
      
 138 
     | 
    
         
            +
                    else
         
     | 
| 
      
 139 
     | 
    
         
            +
                      output[key.to_s] = value
         
     | 
| 
      
 140 
     | 
    
         
            +
                    end
         
     | 
| 
      
 141 
     | 
    
         
            +
                  end
         
     | 
| 
      
 142 
     | 
    
         
            +
                  output
         
     | 
| 
      
 143 
     | 
    
         
            +
                end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                def to_json
         
     | 
| 
      
 146 
     | 
    
         
            +
                  output = to_hash
         
     | 
| 
      
 147 
     | 
    
         
            +
                  output.to_json
         
     | 
| 
      
 148 
     | 
    
         
            +
                end
         
     | 
| 
       130 
149 
     | 
    
         
             
              end
         
     | 
| 
       131 
150 
     | 
    
         | 
| 
       132 
151 
     | 
    
         
             
              class NoAttributeException < StandardError ; end
         
     | 
    
        data/spec/lib/base_spec.rb
    CHANGED
    
    | 
         @@ -267,8 +267,42 @@ describe ActiveRestClient::Base do 
     | 
|
| 
       267 
267 
     | 
    
         
             
                it "calls back to the record_response callback with the url and response body" do
         
     | 
| 
       268 
268 
     | 
    
         
             
                  ActiveRestClient::Connection.any_instance.should_receive(:get).with(any_args).and_return(OpenStruct.new(status:200, headers:{}, body:"Hello world"))
         
     | 
| 
       269 
269 
     | 
    
         
             
                  expect{RecordResponseExample.all}.to raise_error(Exception, "/all|Hello world")
         
     | 
| 
      
 270 
     | 
    
         
            +
                end
         
     | 
| 
      
 271 
     | 
    
         
            +
              end
         
     | 
| 
      
 272 
     | 
    
         
            +
             
     | 
| 
      
 273 
     | 
    
         
            +
              context "JSON output" do
         
     | 
| 
      
 274 
     | 
    
         
            +
                let(:student1) { EmptyExample.new(name:"John Smith", age:31) }
         
     | 
| 
      
 275 
     | 
    
         
            +
                let(:student2) { EmptyExample.new(name:"Bob Brown", age:29) }
         
     | 
| 
      
 276 
     | 
    
         
            +
                let(:location) { EmptyExample.new(place:"Room 1408") }
         
     | 
| 
      
 277 
     | 
    
         
            +
                let(:lazy) { Laz }
         
     | 
| 
      
 278 
     | 
    
         
            +
                let(:object) { EmptyExample.new(name:"Programming 101", location:location, students:[student1, student2]) }
         
     | 
| 
      
 279 
     | 
    
         
            +
                let(:json_parsed_object) { Oj.load(object.to_json) }
         
     | 
| 
      
 280 
     | 
    
         
            +
             
     | 
| 
      
 281 
     | 
    
         
            +
                it "should be able to export to valid json" do
         
     | 
| 
      
 282 
     | 
    
         
            +
                  expect(object.to_json).to_not be_blank
         
     | 
| 
      
 283 
     | 
    
         
            +
                  expect{Oj.load(object.to_json)}.to_not raise_error
         
     | 
| 
      
 284 
     | 
    
         
            +
                end
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
                it "should not be using Object's #to_json method" do
         
     | 
| 
      
 287 
     | 
    
         
            +
                  expect(json_parsed_object["dirty_attributes"]).to be_nil
         
     | 
| 
      
 288 
     | 
    
         
            +
                end
         
     | 
| 
       270 
289 
     | 
    
         | 
| 
      
 290 
     | 
    
         
            +
                it "should recursively convert nested objects" do
         
     | 
| 
      
 291 
     | 
    
         
            +
                  expect(json_parsed_object["location"]["place"]).to eq(location.place)
         
     | 
| 
       271 
292 
     | 
    
         
             
                end
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
                it "should include arrayed objects" do
         
     | 
| 
      
 295 
     | 
    
         
            +
                  expect(json_parsed_object["students"]).to be_an_instance_of(Array)
         
     | 
| 
      
 296 
     | 
    
         
            +
                  expect(json_parsed_object["students"].size).to eq(2)
         
     | 
| 
      
 297 
     | 
    
         
            +
                  expect(json_parsed_object["students"].first["name"]).to eq(student1.name)
         
     | 
| 
      
 298 
     | 
    
         
            +
                  expect(json_parsed_object["students"].second["name"]).to eq(student2.name)
         
     | 
| 
      
 299 
     | 
    
         
            +
                end
         
     | 
| 
      
 300 
     | 
    
         
            +
             
     | 
| 
      
 301 
     | 
    
         
            +
                it "should set integers as a native JSON type" do
         
     | 
| 
      
 302 
     | 
    
         
            +
                  expect(json_parsed_object["students"].first["age"]).to eq(student1.age)
         
     | 
| 
      
 303 
     | 
    
         
            +
                  expect(json_parsed_object["students"].second["age"]).to eq(student2.age)
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
             
     | 
| 
       272 
306 
     | 
    
         
             
              end
         
     | 
| 
       273 
307 
     | 
    
         | 
| 
       274 
308 
     | 
    
         
             
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -7,11 +7,11 @@ require 'webmock/rspec' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            if ENV["JENKINS"]
         
     | 
| 
       8 
8 
     | 
    
         
             
              require 'simplecov-rcov'
         
     | 
| 
       9 
9 
     | 
    
         
             
              SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
         
     | 
| 
      
 10 
     | 
    
         
            +
            elsif ENV["TRAVIS"]
         
     | 
| 
      
 11 
     | 
    
         
            +
              require 'coveralls'
         
     | 
| 
      
 12 
     | 
    
         
            +
              Coveralls.wear!
         
     | 
| 
       10 
13 
     | 
    
         
             
            end
         
     | 
| 
       11 
14 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            require 'coveralls'
         
     | 
| 
       13 
     | 
    
         
            -
            Coveralls.wear!
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
15 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       16 
16 
     | 
    
         
             
              config.color_enabled = true
         
     | 
| 
       17 
17 
     | 
    
         
             
              # config.formatter     = 'documentation'
         
     |