Sha256: d61e274a54784a833d6472b69889afb4b64a89847303b728c7db5f9c23f4dc93
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
module Base module Apis class Search include HTTP include Apis attr_reader :client_secret attr_accessor :request_parameters, :uri def request(query, &block) send(:request_parameters=, query, &block) send(:uri=, request_parameters) request = generate_request(uri) start(request, uri) end private def request_parameters=(query) # https://github.com/baseinc/api-docs/blob/master/base_api_v1_search.md # # { client_id: 'client id for search', # client_secret: 'client secret for search', # q: 'search words delimited by space', # sort: 'order_count desc, stock desc, price asc', # start: 0, # size: 10, # fields: 'shop_name, title, detail', # shop_id: '' } given_parameters = block_given? ? yield : {} default = { client_id: @client_secret.search_client_id, client_secret: @client_secret.search_client_secret } @request_parameters = default.merge(given_parameters).merge(q: query) end def uri=(request_parameters) @uri = URI([ API_HOST, "/#{API_VERSION}/search?", URI.encode_www_form(request_parameters)].join) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
base-api-client-0.3.1.beta | lib/base/apis/search.rb |
base-api-client-0.3.beta | lib/base/apis/search.rb |