class Masheri::RpcClient::Response
Constants
- MASHERY_WAIT_TIME
Can't call Mashery too many times, or they get mad
Public Class Methods
new(query_builder)
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 4 def initialize(query_builder) @query_builder = query_builder @json = query_builder.to_json end
Public Instance Methods
current_page()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 70 def current_page result["current_page"] end
error()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 13 def error @json["error"] end
error?()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 36 def error? error.present? end
find_each(&block)
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 27 def find_each(&block) to_objects.each(&block) if next_page? response = next_page! response.find_each(&block) end end
items()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 17 def items result["items"] end
items_per_page()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 74 def items_per_page result["items_per_page"] end
length()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 40 def length items.length end
more_pages?()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 44 def more_pages? current_page < total_pages end
Also aliased as: next_page?
next_page!()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 57 def next_page! sleep(MASHERY_WAIT_TIME) Response.new(@query_builder.page(next_page_number)) end
next_page_number()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 50 def next_page_number current_page + 1 end
result()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 9 def result @json["result"] end
to_objects()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 21 def to_objects items.map do |item| @query_builder.reify(item) end end
total_items()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 62 def total_items result["total_items"] end
total_pages()
click to toggle source
# File lib/masheri/rpc_client/response.rb, line 66 def total_pages result["total_pages"] end