Module: RapidAPI
- Defined in:
- lib/rapidapisdk.rb,
lib/rapidapi/version.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
'0.1.3'
Class Method Summary collapse
- .build_request(uri, form_data) ⇒ Object
- .build_uri(package, block) ⇒ Object
- .call(package_name, block_name, args = {}) ⇒ Object
- .config(**args) ⇒ Object
Class Method Details
.build_request(uri, form_data) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rapidapisdk.rb', line 34 def build_request(uri, form_data) config = RapidAPI::Config req = Net::HTTP::Post::Multipart.new(uri, form_data) req.basic_auth(config.project, config.token) req end |
.build_uri(package, block) ⇒ Object
30 31 32 |
# File 'lib/rapidapisdk.rb', line 30 def build_uri(package, block) URI("http://rapidapi.io/connect/#{package}/#{block}") end |
.call(package_name, block_name, args = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rapidapisdk.rb', line 14 def call(package_name, block_name, args={}) uri = build_uri(package_name, block_name) req = build_request(uri, args) res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) } reply = JSON.parse(res.body) unless res.code.to_i == 200 reply['outcome'] = 'error' end reply end |