Reputation: 3049
I'm currently working with Httparty
to make a GET
Seamless.giv API which returns field from a form. In the requests there are Authentication headers that need to be passed in order to access the API. But the request has to be made to a specific form. Thats where the issue lays should this be in the base URI or appended?
Here is the curl
example of the request:
curl -X GET -H "AuthDate: 1531236159"\
-H "Authorization: HMAC-SHA256 api_key=XXXXXXXX nonce=12345 Signature=XXXXXXXXXXX"\
-d 'false' https://nycopp.seamlessdocs.com/api/form/:form_id/elements
and this is the approach im currently taking:
class SeamlessGov
include HTTParty
base_uri "https://nycopp.seamlessdocs.com/api"
def initialize(args={})
@api_key = args[:api_key]
@nonce = args[:nonce]
@signature = generate_signature
end
def form(form_id)
@form = form_id
end
def headers(headers={})
@headers = headers
end
def generate_signature
# bash command
end
end
Is the best practice to append it or put it in the base_uri
for example:
base_uri "https://nycopp.seamlessdocs.com/api/form/:form_id/elements"
or created a method to append to the base_uri
for example:
def append_form(form)
"/form/#{form}/elements"
end
What would the best approach be? So that when I call
@form = SeamlessGov.new(params, headers)
works.
Upvotes: 0
Views: 478
Reputation: 11
If I understand what you're asking correctly, you would write a method like:
def create_form
get("/form/#{form_id}/elements", headers)
end
Which you can then call like:
@form = SeamlessGov.new(params, headers).create_form
Upvotes: 1