Method: PlaylyfeClient::Connection#api

Defined in:
lib/playlyfe_client/connection.rb

#api(method, route, query = {}, body = {}, raw = false) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/playlyfe_client/connection.rb', line 120

def api(method, route, query = {}, body = {}, raw = false)
  query = check_token(query)
  begin
    uri="https://api.playlyfe.com/#{@version}#{route}?#{query}"
    puts "doing real query to api.uri : #{uri} with body #{body.to_json}" 
    response = RestClient::Request.execute(
      :method => method,
      :url => uri,
      :headers => {
        :content_type => :json,
        :accepts => :json
      },
      :payload => body.to_json,
      :ssl_version => 'SSLv23'
    )

    if raw == true
      return response.body
    else
      if response.body == 'null'
        return nil
      else
        return JSON.parse(response.body)
      end
    end
  rescue => e
    raise PlaylyfeClient::Error.build(e.response, "#{method} #{uri}")
  end
end