class BandCampBX::Net
Attributes
client[R]
Public Class Methods
new(client)
click to toggle source
# File lib/bandcampbx/net.rb, line 7 def initialize(client) @client = client end
Public Instance Methods
key()
click to toggle source
# File lib/bandcampbx/net.rb, line 15 def key client.key end
post(endpoint, options={})
click to toggle source
# File lib/bandcampbx/net.rb, line 19 def post(endpoint, options={}) raw_post(endpoint, options) # map_response(raw_post(endpoint, options)) end
secret()
click to toggle source
# File lib/bandcampbx/net.rb, line 11 def secret client.secret end
Private Instance Methods
auth_options()
click to toggle source
# File lib/bandcampbx/net.rb, line 33 def auth_options { user: key, pass: secret } end
base_url()
click to toggle source
# File lib/bandcampbx/net.rb, line 29 def base_url 'https://campbx.com/api/' end
raw_post(endpoint, options)
click to toggle source
# For some crazy reason, CampBX is returning ruby hash strings rather than # JSON objects right now ಠ_ಠ I’m just going to gsub ‘=>’ to ‘:’ to ‘solve’ # it for now. Not thrilled with this. def map_response(wish_this_were_reliably_json)
wish_this_were_reliably_json.gsub('=>', ':')
end
# File lib/bandcampbx/net.rb, line 47 def raw_post(endpoint, options) uri = URI url_for(endpoint) http = ::Net::HTTP::Persistent.new 'bandcampbx' post = ::Net::HTTP::Post.new uri.path post.set_form_data options.merge(auth_options) http.request(uri, post).body end
url_for(endpoint)
click to toggle source
# File lib/bandcampbx/net.rb, line 25 def url_for(endpoint) base_url + endpoint end