Add WFM connection class and specs IGNT-3539#1
Conversation
bedrock-adam
left a comment
There was a problem hiding this comment.
Nice Tony!
We're putting these ones out for a wider team approval before merge too, right @lankz?
lib/xpm_ruby/connection.rb
Outdated
| end | ||
|
|
||
| def get(endpoint:) | ||
| Faraday.new("https://#{@api_url}/v3/#{endpoint}", headers: { "Authorization" => @basic_auth }).get |
There was a problem hiding this comment.
This is the guts of the PR. My feeling (my general feeling) is to split these out as much as possible. Something like:
ENDPOINTS = {
staff_list: 'staff.api/list'
}.freeze
def setup(endpoint:)
@setup = @connector.new(url(endpoint), headers: headers)
end
def call
@response = @setup.get
end
def url(endpoint)
"https://#{@api_url}/v3/#{ENDPOINTS[endpoint]}"
end
def headers
{
"Authorization" => @basic_auth
}
endWhat do you think of such a generalised approach? I'm thinking to take that approach because it's a gem.
BTW, this is great! 😄
There was a problem hiding this comment.
Hmm I am still inclined to generalise later rather than sooner. For example, we can't set call to a get because sometimes it will have to be a post or a put or a delete. The less you do up front, the less you have to undo as the specifications become clearer (when the new endpoints get added).
There was a problem hiding this comment.
I'm thinking if XPM ever changes its endpoints, you only have to make a change in the gem (any code using the gem is insulated).
connection.get(endpoint: "staff.api/list")There was a problem hiding this comment.
Also think about the perspective of the service calling this. It will have to do a new, setup and then call?
There was a problem hiding this comment.
Also not sure that a connector should have the list of endpoints on it...
There was a problem hiding this comment.
I don't really want to derail you; I'm just bringing up generalisation because I think early generalisation (that is, just insulation really) will save time later (because it's a gem).
There was a problem hiding this comment.
I'm just thinking maybe something like:
connection = XpmRuby::Connection.new(api_key: "api_key", api_url: "api.workflowmax.com", account_key: "account_key")
connection.staff_listThere was a problem hiding this comment.
At the moment we are going to let the caller specify the endpoint (e.g. Xpm::Staff will have a method called list_all which will call connection.get('staff.api/list'))
There was a problem hiding this comment.
Ok, I discussed this with @wizardofosmium and made appropriate changes. :)
Add WFM connection class and specs
Connect to WorkFlow max using a connection object.
I am initially adding a
getmethod.post,putanddeleteto follow.You can initialise it with the account_key, api_key and api_url
We create the basic_auth key on instantiation. Also we are using Faraday as the library to handle HTTP requests.