-
Notifications
You must be signed in to change notification settings - Fork 1
add Staff.list IGNT-3540 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4e46189
add Staff.list
bedrock-adam b8652e2
fix model namespace
bedrock-adam dacb708
remove extra line
bedrock-adam b11ff55
drop sax parser
bedrock-adam d8399bf
remove parser spec
bedrock-adam 66282cc
optimise
bedrock-adam d9e61cf
fix payroll_code
bedrock-adam 05de0bc
add dry typesa
bedrock-adam 9ec0987
Revert "add dry typesa"
bedrock-adam e5f2225
superclass errors + add api_url
bedrock-adam 0cab705
Merge branch 'master' of github.com:ignitionapp/xpm_ruby into staff/list
bedrock-adam 0273143
update to use Connection
bedrock-adam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| require "xpm_ruby/version" | ||
|
|
||
| require "xpm_ruby/connection" | ||
|
|
||
| module XpmRuby | ||
| class Error < StandardError; end | ||
| # Your code goes here... | ||
| class Unauthorized < Error; end | ||
| end | ||
|
|
||
| require "xpm_ruby/version" | ||
| require "xpm_ruby/connection" | ||
| require "xpm_ruby/staff" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| module XpmRuby | ||
| module Models | ||
| class Staff | ||
| attr_accessor :uuid, :name, :email, :phone, :mobile, :address, :payroll_code | ||
|
|
||
| def initialize(uuid: nil, name: nil, email: nil, phone: nil, mobile: nil, | ||
| address: nil, payroll_code: nil) | ||
| @uuid = uuid | ||
| @name = name | ||
| @email = email | ||
| @phone = phone | ||
| @mobile = mobile | ||
| @address = address | ||
| @payroll_code = payroll_code | ||
| end | ||
|
|
||
| def ==(other) | ||
| uuid == other.uuid | ||
| end | ||
|
|
||
| def eql?(other) | ||
| self == other | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| require "ox" | ||
|
|
||
| require_relative "models/staff" | ||
|
|
||
| module XpmRuby | ||
| module Staff | ||
| extend self | ||
|
|
||
| class Error < Error; end | ||
|
|
||
| def build(**args) | ||
| Models::Staff.new(args) | ||
| end | ||
|
|
||
| def list(api_key:, account_key:, api_url:) | ||
| response = Connection | ||
| .new(api_key: api_key, account_key: account_key, api_url: api_url) | ||
| .get(endpoint: "staff.api/list") | ||
|
|
||
| case response.status | ||
| when 401 | ||
| hash = Ox.load(response.body, mode: :hash_no_attrs, symbolize_keys: false) | ||
|
|
||
| raise Unauthorized.new(hash["html"]["head"]["title"]) | ||
| when 200 | ||
| hash = Ox.load(response.body, mode: :hash_no_attrs, symbolize_keys: false) | ||
|
|
||
| case hash["Response"]["Status"] | ||
| when "OK" | ||
| hash["Response"]["StaffList"]["Staff"].map do |staff| | ||
| Models::Staff.new( | ||
| uuid: staff["UUID"], | ||
| name: staff["Name"], | ||
| email: staff["Email"], | ||
| phone: staff["Phone"], | ||
| mobile: staff["Mobile"], | ||
| address: staff["Address"], | ||
| payroll_code: staff["PayrollCode"]) | ||
| end | ||
| when "ERROR" | ||
| raise Error.new(response["ErrorDescription"]) | ||
| end | ||
| else | ||
| raise Error.new(response.status) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require "spec_helper" | ||
|
|
||
| module XpmRuby | ||
| RSpec.describe(Staff) do | ||
| describe ".list" do | ||
| context "when keys invalid" do | ||
| let(:api_key) { "" } | ||
| let(:account_key) { "" } | ||
| let(:api_url) { "api.workflowmax.com" } | ||
|
|
||
| xit "raises unauthorized error" do | ||
| expect do | ||
| Staff.list(api_key: api_key, account_key: account_key, api_url: api_url) | ||
| end.to raise_error(Unauthorized) | ||
| end | ||
| end | ||
|
|
||
| context "when keys valid" do | ||
| let(:api_key) { "" } | ||
| let(:account_key) { "" } | ||
| let(:api_url) { "api.workflowmax.com" } | ||
|
|
||
| xit "lists staff" do | ||
| expect( | ||
| Staff.list(api_key: api_key, account_key: account_key, api_url: api_url) | ||
| ).to include( | ||
| Staff.build( | ||
| name: "Dev Testing", | ||
| email: "dev@practiceignition.com", | ||
| uuid: "8c79202e-caf8-4a12-a3d7-ac338e50741f")) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Integration with VCR soon |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For later (not this PR), maybe we should create an ConnectionErrors module (might help us DRY up the code a bit)? What do you think @subskii ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess let's see how this develops. :)