117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/notehub/notehub.rb', line 117
def get_api(params)
params['version'] = API_VERSION
uri = URI("http://www.notehub.org/api/note#{params.to_query}")
Net::HTTP.start(uri.host, uri.port) do |http|
req = Net::HTTP::Get.new uri
res = http.request req
if res && res.code == "200"
json = JSON.parse(res.body)
if json['status']['success']
return json
else
raise "GET request returned error: #{json['status']['message']}"
end
else
p res.body if res
raise "Error retrieving GET request to API"
end
end
end
|