-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from mollie/terminals-api
Add Terminals API
- Loading branch information
Showing
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
terminal = Mollie::Terminal.get("term_7MgL4wea46qkRcoTZjWEH") |
This file contains 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 @@ | ||
terminals = Mollie::Terminal.all |
This file contains 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 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,59 @@ | ||
module Mollie | ||
class Terminal < Base | ||
|
||
STATUS_PENDING = "pending".freeze | ||
STATUS_ACTIVE = "active".freeze | ||
STATUS_INACTIVE = "inactive".freeze | ||
|
||
attr_accessor :id, | ||
:profile_id, | ||
:status, | ||
:brand, | ||
:model, | ||
:serial_number, | ||
:currency, | ||
:description, | ||
:created_at, | ||
:updated_at, | ||
:deactivated_at, | ||
:_links | ||
|
||
alias links _links | ||
|
||
def pending? | ||
status == STATUS_PENDING | ||
end | ||
|
||
def active? | ||
status == STATUS_ACTIVE | ||
end | ||
|
||
def inactive? | ||
status == STATUS_INACTIVE | ||
end | ||
|
||
def created_at=(created_at) | ||
@created_at = begin | ||
Time.parse(created_at.to_s) | ||
rescue StandardError | ||
nil | ||
end | ||
end | ||
|
||
def updated_at=(updated_at) | ||
@updated_at = begin | ||
Time.parse(updated_at.to_s) | ||
rescue StandardError | ||
nil | ||
end | ||
end | ||
|
||
def deactivated_at=(deactivated_at) | ||
@deactivated_at = begin | ||
Time.parse(deactivated_at.to_s) | ||
rescue StandardError | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains 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,23 @@ | ||
{ | ||
"id": "term_7MgL4wea46qkRcoTZjWEH", | ||
"profileId": "pfl_QkEhN94Ba", | ||
"status": "active", | ||
"brand": "PAX", | ||
"model": "A920", | ||
"serialNumber": "1234567890", | ||
"currency": "EUR", | ||
"description": "Terminal #12345", | ||
"createdAt": "2022-02-12T11:58:35.0Z", | ||
"updatedAt": "2022-11-15T13:32:11+00:00", | ||
"deactivatedAt": "2022-02-12T12:13:35.0Z", | ||
"_links": { | ||
"self": { | ||
"href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", | ||
"type": "application/hal+json" | ||
}, | ||
"documentation": { | ||
"href": "https://docs.mollie.com/reference/v2/terminals-api/get-terminal", | ||
"type": "text/html" | ||
} | ||
} | ||
} |
This file contains 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,34 @@ | ||
{ | ||
"count": 3, | ||
"_embedded": { | ||
"terminals": [ | ||
{ | ||
"resource": "terminal", | ||
"id": "terminal_one" | ||
}, | ||
{ | ||
"resource": "terminal", | ||
"id": "terminal_two" | ||
}, | ||
{ | ||
"resource": "terminal", | ||
"id": "terminal_three" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"self": { | ||
"href": "https://api.mollie.com/v2/terminals", | ||
"type": "application/hal+json" | ||
}, | ||
"previous": null, | ||
"next": { | ||
"href": "https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH", | ||
"type": "application/hal+json" | ||
}, | ||
"documentation": { | ||
"href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals", | ||
"type": "text/html" | ||
} | ||
} | ||
} |
This file contains 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,54 @@ | ||
require 'helper' | ||
|
||
module Mollie | ||
class TerminalTest < Test::Unit::TestCase | ||
GET_TERMINAL = read_fixture('terminals/get.json') | ||
LIST_TERMINALS = read_fixture('terminals/list.json') | ||
|
||
def test_get_terminal | ||
stub_request(:get, "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH") | ||
.to_return(status: 200, body: GET_TERMINAL, headers: {}) | ||
|
||
terminal = Terminal.get("term_7MgL4wea46qkRcoTZjWEH") | ||
|
||
assert_equal "term_7MgL4wea46qkRcoTZjWEH", terminal.id | ||
assert_equal "pfl_QkEhN94Ba", terminal.profile_id | ||
assert_equal "active", terminal.status | ||
assert_equal "PAX", terminal.brand | ||
assert_equal "A920", terminal.model | ||
assert_equal "1234567890", terminal.serial_number | ||
assert_equal "EUR", terminal.currency | ||
assert_equal "Terminal #12345", terminal.description | ||
assert_equal Time.parse("2022-02-12T11:58:35.0Z"), terminal.created_at | ||
assert_equal Time.parse("2022-11-15T13:32:11+00:00"), terminal.updated_at | ||
assert_equal Time.parse("2022-02-12T12:13:35.0Z"), terminal.deactivated_at | ||
end | ||
|
||
def test_status_pending | ||
assert Terminal.new(status: Terminal::STATUS_PENDING).pending? | ||
assert !Terminal.new(status: "not-pending").pending? | ||
end | ||
|
||
def test_status_active | ||
assert Terminal.new(status: Terminal::STATUS_ACTIVE).active? | ||
assert !Terminal.new(status: "not-active").active? | ||
end | ||
|
||
def test_status_inactive | ||
assert Terminal.new(status: Terminal::STATUS_INACTIVE).inactive? | ||
assert !Terminal.new(status: "not-inactive").inactive? | ||
end | ||
|
||
def test_list_terminals | ||
stub_request(:get, "https://api.mollie.com/v2/terminals") | ||
.to_return(status: 200, body: LIST_TERMINALS, headers: {}) | ||
|
||
terminals = Terminal.all | ||
|
||
assert_equal 3, terminals.size | ||
assert_equal "terminal_one", terminals[0].id | ||
assert_equal "terminal_two", terminals[1].id | ||
assert_equal "terminal_three", terminals[2].id | ||
end | ||
end | ||
end |