class Ruspider::RestClient
ChemSpider
REST Webservice API Client
Constants
- HOST_NAME
Public Class Methods
new(token, header = {})
click to toggle source
# File lib/ruspider/rest_client.rb, line 12 def initialize(token, header = {}) @token = token @header = header end
Public Instance Methods
post(api, op, options = {})
click to toggle source
# File lib/ruspider/rest_client.rb, line 27 def post(api, op, options = {}) return -1 if op.empty? ops = { token: @token }.merge(options) res = HTTParty.post( "https://#{HOST_NAME}/#{api}/#{op}", header: { header: @header }, body: ops, query_string_normalizer: ->(h) { query_string_normalizer(h) } ) raise "#{res.response.code}: #{res.parsed_response}" unless res.success? res.response.body end
query_string_normalizer(query)
click to toggle source
# File lib/ruspider/rest_client.rb, line 17 def query_string_normalizer(query) query.to_hash.map do |k, v| if v.class == Array v.map { |x| "#{k}=#{x}" }.join('&') else HTTParty::HashConversions.normalize_param(k, v) end end.join end