Class: TinyAppstoreConnect::Response
- Inherits:
-
Object
- Object
- TinyAppstoreConnect::Response
- Extended by:
- Forwardable
- Defined in:
- lib/tiny_appstore_connect/response.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #all_pages(flatten: false, &block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(response, client) ⇒ Response
constructor
A new instance of Response.
- #next_page {|url| ... } ⇒ Object
- #next_pages(count: 1, &block) ⇒ Object
- #next_url ⇒ Object
- #rate ⇒ Object
- #request_url ⇒ Object
- #to_model ⇒ Object
- #to_models ⇒ Object
Constructor Details
#initialize(response, client) ⇒ Response
Returns a new instance of Response.
15 16 17 18 |
# File 'lib/tiny_appstore_connect/response.rb', line 15 def initialize(response, client) @response = response @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/tiny_appstore_connect/response.rb', line 13 def client @client end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/tiny_appstore_connect/response.rb', line 13 def response @response end |
Instance Method Details
#all_pages(flatten: false, &block) ⇒ Object
74 75 76 77 |
# File 'lib/tiny_appstore_connect/response.rb', line 74 def all_pages(flatten: false, &block) responses = next_pages(count: nil, &block) flatten ? responses.flat_map(&:to_models) : responses end |
#each(&block) ⇒ Object
90 91 92 93 94 |
# File 'lib/tiny_appstore_connect/response.rb', line 90 def each(&block) to_models.each do |model| yield(model) end end |
#next_page {|url| ... } ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tiny_appstore_connect/response.rb', line 47 def next_page(&block) url = next_url return if url.nil? return client.get(url) unless block_given? yield(url) end |
#next_pages(count: 1, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tiny_appstore_connect/response.rb', line 55 def next_pages(count: 1, &block) count = 0 if !count.nil? && count < 0 responses = [self] counter = 0 resp = self loop do resp = resp.next_page(&block) break if resp.nil? responses << resp counter += 1 break if !count.nil? && counter >= count end responses end |
#next_url ⇒ Object
40 41 42 43 44 45 |
# File 'lib/tiny_appstore_connect/response.rb', line 40 def next_url return if body.nil? links = body['links'] || {} links['next'] end |
#rate ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tiny_appstore_connect/response.rb', line 26 def rate return {} unless value = response.headers[:x_rate_limit] value.split(';').inject({}) do |r, q| k, v = q.split(':') case k when 'user-hour-lim' r.merge!(limit: v) when 'user-hour-rem' r.merge!(remaining: v) end end end |
#request_url ⇒ Object
22 23 24 |
# File 'lib/tiny_appstore_connect/response.rb', line 22 def request_url @response.env.url end |
#to_model ⇒ Object
79 80 81 |
# File 'lib/tiny_appstore_connect/response.rb', line 79 def to_model to_models.first end |