Module: RapidAPI
- Defined in:
- lib/rapid_api.rb,
lib/rapid_api/version.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
'0.1.0'
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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rapid_api.rb', line 40 def build_request(uri, form_data) config = RapidAPI::Config # Create request req = Net::HTTP::Post.new(uri) # Set project credentials req.basic_auth(config.project, config.api_key) # Add arguments req.set_form_data(form_data) req end |
.build_uri(package, block) ⇒ Object
36 37 38 |
# File 'lib/rapid_api.rb', line 36 def build_uri(package, block) URI("http://rapidapi.io/connect/#{package}/#{block}") end |
.call(package_name, block_name, args = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rapid_api.rb', line 12 def call(package_name, block_name, args={}) # Create URI uri = build_uri(package_name, block_name) req = build_request(uri, args) # Execute res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) } # Jsonify reply = JSON.parse(res.body) # Check for request errors unless res.code.to_i == 200 reply['outcome'] = 'error' reply['payload'] = 'Networking error' end # Return result reply end |