Class: InsoundApi::Request
- Inherits:
-
Object
- Object
- InsoundApi::Request
- Defined in:
- lib/insound_api/request.rb
Constant Summary collapse
- BASE_URL =
"https://www.insound.com/ws/affiliate/"
- VALID_FORMATS =
%w{all vinyl seveninch digital poster shirt cd}
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #affiliate_id ⇒ Object
- #api_password ⇒ Object
- #base_url_with_creds ⇒ Object
- #build_params ⇒ Object
- #build_response(data) ⇒ Object
- #build_url ⇒ Object
- #get_response ⇒ Object
-
#initialize(opts = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(opts = {}) ⇒ Request
Returns a new instance of Request.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/insound_api/request.rb', line 14 def initialize(opts={}) unless opts[:artist] raise RequestException, ":artist is a required param for any request" end if opts[:format] && !VALID_FORMATS.include?(opts[:format].downcase) raise RequestException, ":format must be one of the follwing: #{VALID_FORMATS.join(', ')}" end @params = opts end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/insound_api/request.rb', line 12 def params @params end |
Class Method Details
Instance Method Details
#affiliate_id ⇒ Object
63 64 65 |
# File 'lib/insound_api/request.rb', line 63 def affiliate_id InsoundApi.config.affiliate_id end |
#api_password ⇒ Object
67 68 69 |
# File 'lib/insound_api/request.rb', line 67 def api_password InsoundApi.config.api_password end |
#base_url_with_creds ⇒ Object
71 72 73 |
# File 'lib/insound_api/request.rb', line 71 def base_url_with_creds "#{BASE_URL}?id=#{affiliate_id}&password=#{api_password}" end |
#build_params ⇒ Object
46 47 48 |
# File 'lib/insound_api/request.rb', line 46 def build_params {param_name => params} end |
#build_response(data) ⇒ Object
42 43 44 |
# File 'lib/insound_api/request.rb', line 42 def build_response(data) Response.new(:raw_xml => data.to_str, :request => self) end |
#build_url ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/insound_api/request.rb', line 50 def build_url url = base_url_with_creds if params.any? parts = [] params.each_pair do |name, value| parts << "#{URI.escape(name.to_s)}=#{URI.escape(value.to_s)}" end url = "#{url}&#{parts.join('&')}" end url end |
#get_response ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/insound_api/request.rb', line 31 def get_response data = RestClient.get(build_url) response = data ? build_response(data) : nil if response.errors? raise RequestException, "The following errors were returned: #{response.errors.inspect}" else response end end |