bookingsync-api 0.0.16 → 0.0.17

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: 08d6720058ec3d13d13447f1ceb97e39b44740d6
4
- data.tar.gz: 1050fdba11d3ce21578028d35269484c31b9a288
3
+ metadata.gz: 297041c927ac94cf6fd56b2c8994adc58a5d2962
4
+ data.tar.gz: b9b106fc73c0ca792bb5c899916d636f2bd02b77
5
5
  SHA512:
6
- metadata.gz: 08824e7c2896b4a51e38134c81758a212473b53ab481d4ce12cc17aca94ff7b04fea1d44ecee8085fc20caae3e487adb6a37fc102575fa77d9f8cc61c48c3b33
7
- data.tar.gz: 5a8cfb28de21e09172eca667234c3ce08d4475c2f5b707380d2cd5894943b2bd720116f5f72a15fb04e2d819d8ca02d50e293b400f7bcf2941f96b52e1091d0a
6
+ metadata.gz: 90c91f15b4ee3f3a8aa0cf0d23510372c8ffb80b92598b0d1fe08a8bddc6f6c135c1d95ae3d3c85dd61bed572f6e284147c7b76772d90c61bd7e44255eb29441
7
+ data.tar.gz: 8287a9f009569a5dc5780817a9ef1c915f7f3106d1f3b9777466dfad6a1cc118321ba308f1b660ce658e0c0c5b1efd255785daeff758e4dbfbe3c8f95a03897c
data/README.md CHANGED
@@ -45,6 +45,14 @@ Fetch all resources (with multiple requests under the hood) and return one big a
45
45
 
46
46
  api.bookings(auto_paginate: true) => [BookingSync::API::Resource, BookingSync::API::Resource, ...]
47
47
 
48
+ ### Meta information
49
+
50
+ Some endpoints return additional info about resource in meta section. To fetch it you need to
51
+ access last response.
52
+
53
+ api.rentals(updated_since: "2014-01-01 15:43:96 UTC") # => [BookingSync::API::Resource, BookingSync::API::Resource, ...]
54
+ api.last_response.meta # => {"deleted_rentals_ids" => [1, 3, 4]}
55
+
48
56
  ### Logging
49
57
 
50
58
  Sometimes it's useful to see what data bookingsync-api gem sends and what it
@@ -53,7 +53,7 @@ module BookingSync::API
53
53
 
54
54
  MEDIA_TYPE = "application/vnd.api+json"
55
55
 
56
- attr_reader :token, :logger
56
+ attr_reader :token, :logger, :last_response
57
57
 
58
58
  def_delegator :@instrumenter, :instrument
59
59
 
@@ -283,7 +283,7 @@ module BookingSync::API
283
283
  # @raise [BookingSync::API::UnprocessableEntity] - On validations error
284
284
  # @return [BookingSync::API::Response|NilClass]
285
285
  def handle_response(faraday_response)
286
- response = Response.new(self, faraday_response)
286
+ @last_response = response = Response.new(self, faraday_response)
287
287
  case response.status
288
288
  when 204; nil # destroy/cancel
289
289
  when 200..299; response
@@ -2,7 +2,7 @@ require "addressable/template"
2
2
 
3
3
  module BookingSync::API
4
4
  class Response
5
- SPECIAL_JSONAPI_FIELDS = %w(links linked meta)
5
+ SPECIAL_JSONAPI_FIELDS = [:links, :linked, :meta]
6
6
  attr_reader :client, :status, :headers, :data, :relations, :body
7
7
 
8
8
  # Build a Response after a completed request.
@@ -34,8 +34,8 @@ module BookingSync::API
34
34
  #
35
35
  # @return [Symbol] Key name in the body hash
36
36
  def resources_key
37
- decoded_body.keys.delete_if { |k|
38
- SPECIAL_JSONAPI_FIELDS.include?(k)
37
+ decoded_body.keys.delete_if { |key|
38
+ SPECIAL_JSONAPI_FIELDS.include?(key)
39
39
  }.pop
40
40
  end
41
41
 
@@ -59,11 +59,18 @@ module BookingSync::API
59
59
  # Return a Hash of relations to other pages built from 'Link'
60
60
  # response header
61
61
  #
62
- # @return [Hash] Hash of relations to first,last,next and prev pages
62
+ # @return [Hash] Hash of relations to first, last, next and prev pages
63
63
  def relations
64
64
  @relations ||= process_rels
65
65
  end
66
66
 
67
+ # Returns a Hash of meta information taken from the response body
68
+ #
69
+ # @return [Hash] Meta hash
70
+ def meta
71
+ @meta ||= decoded_body[:meta]
72
+ end
73
+
67
74
  private
68
75
 
69
76
  def decoded_body
@@ -1,5 +1,5 @@
1
1
  module BookingSync
2
2
  module API
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.17"
4
4
  end
5
5
  end
@@ -227,4 +227,12 @@ describe BookingSync::API::Client do
227
227
  end
228
228
  end
229
229
  end
230
+
231
+ describe "#last_response" do
232
+ it "returns last response" do
233
+ stub_get("resources", body: {meta: {count: 10}, resources: []}.to_json)
234
+ client.get("resources")
235
+ expect(client.last_response.meta).to eql(count: 10)
236
+ end
237
+ end
230
238
  end
@@ -20,7 +20,8 @@ describe BookingSync::API::Response do
20
20
  conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
21
21
  conn.adapter :test, @stubs do |stub|
22
22
  stub.get '/rentals' do
23
- body = {links: links, rentals: rentals}.to_json
23
+ body = {links: links, rentals: rentals,
24
+ meta: {count: 10}}.to_json
24
25
  [200, headers, body]
25
26
  end
26
27
  end
@@ -69,4 +70,10 @@ describe BookingSync::API::Response do
69
70
  expect(response.relations[:last].href).to eql('/rentals?page=19')
70
71
  end
71
72
  end
73
+
74
+ describe "#meta" do
75
+ it "returns meta information from response body" do
76
+ expect(response.meta).to eql(count: 10)
77
+ end
78
+ end
72
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookingsync-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Grosjean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday