active_rest_client 0.9.67 → 0.9.68

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bad00208370951aee8feea5b4880654dc658d124
4
- data.tar.gz: 4fb5e5c094fe3482f1ac9ad24955bce475e0dd0d
3
+ metadata.gz: 165810386481e53bc5f8720c4f655a5a135dea49
4
+ data.tar.gz: 16f2ccfac3c0fb433d7466ba5c45915da4bdc698
5
5
  SHA512:
6
- metadata.gz: 104fdb894bda35c42fe84a536b546b17aeeba7fb667bb0facf020cc1ee3b77c5b5c8c79c9e22c24c81a2824e9cafc7003a56280a2a7f735fe4083ac21aa2f0f2
7
- data.tar.gz: 21c02661cea31ccff13ee10245396b1459c541aa5f9fa5fab70b01420b88ba5319473f8b4aeae9d67c90e8e9a0278acdfacfa51a379477f0962f1b0d74f90c3f
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
@@ -1,3 +1,3 @@
1
1
  module ActiveRestClient
2
- VERSION = "0.9.67"
2
+ VERSION = "0.9.68"
3
3
  end
@@ -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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.67
4
+ version: 0.9.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - Which Ltd