class Lbry::Api
Attributes
auth[RW]
default_options[RW]
Public Class Methods
new(auth: {})
click to toggle source
# File lib/lbry/api.rb, line 21 def initialize(auth: {}) @auth = { username: auth["user"], password: auth["password"] } @default_options = {} default_options[:basic_auth] = auth if auth.values.any? end
Public Instance Methods
get(lbry_command, lbry_params = {}, options: {})
click to toggle source
# File lib/lbry/api.rb, line 34 def get(lbry_command, lbry_params = {}, options: {}) request(:get, lbry_command, lbry_params) end
parse_response(raw_response)
click to toggle source
# File lib/lbry/api.rb, line 12 def parse_response(raw_response) # binding.pry struct = JSON.parse(raw_response.body, object_class: OpenStruct) error = struct.error return struct unless error && error.code && error.message # binding.pry raise Lbry::ApiError.new(error) end
post(lbry_command, *lbry_params)
click to toggle source
# File lib/lbry/api.rb, line 38 def post(lbry_command, *lbry_params) headers = { "Content-Type" => "application/x-www-form-urlencoded" } request(:post, lbry_command, *lbry_params, headers: headers) end
put(lbry_command, lbry_params = {}, options: {})
click to toggle source
# File lib/lbry/api.rb, line 43 def put(lbry_command, lbry_params = {}, options: {}) request(:put, lbry_command, lbry_params) end
request(http_verb, lbry_command, lbry_params, headers: {})
click to toggle source
# File lib/lbry/api.rb, line 27 def request(http_verb, lbry_command, lbry_params, headers: {}) params = { body: { method: lbry_command, params: lbry_params }.to_json } params[:headers] = headers if headers.keys.any? response = self.class.send(http_verb, '', params) parse_response(response) end