Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@ PATH
remote: .
specs:
xpm_ruby (0.1.0)
faraday
faraday (~> 1)
ox (~> 2.13)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
byebug (11.1.3)
coderay (1.1.2)
diff-lcs (1.3)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
jaro_winkler (1.5.4)
method_source (1.0.0)
multipart-post (2.1.1)
ox (2.13.2)
parallel (1.19.1)
parser (2.7.0.5)
ast (~> 2.4.0)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
rainbow (3.0.0)
rake (13.0.1)
rspec (3.9.0)
Expand Down Expand Up @@ -48,6 +59,8 @@ PLATFORMS

DEPENDENCIES
bundler (~> 2.0)
byebug (~> 11)
pry-byebug (~> 3)
rake (>= 12.3.3)
rspec (~> 3.0)
rubocop (= 0.77.0)
Expand Down
10 changes: 5 additions & 5 deletions lib/xpm_ruby.rb
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"
26 changes: 26 additions & 0 deletions lib/xpm_ruby/models/staff.rb
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
48 changes: 48 additions & 0 deletions lib/xpm_ruby/staff.rb
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
Copy link
Contributor

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 ?

Copy link
Contributor

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. :)

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
35 changes: 35 additions & 0 deletions spec/staff_spec.rb
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
Copy link
Contributor Author

@bedrock-adam bedrock-adam Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration with VCR soon

6 changes: 5 additions & 1 deletion xpm_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("rubocop", "0.77.0")
spec.add_development_dependency("rubocop-rspec")

spec.add_runtime_dependency("faraday")
spec.add_development_dependency("byebug", "~> 11")
spec.add_development_dependency("pry-byebug", "~> 3")

spec.add_runtime_dependency("faraday", "~> 1")
spec.add_runtime_dependency("ox", "~> 2.13")
end