-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated gem structure. implmented :all, :find and :update for forms.
- Loading branch information
1 parent
aa49381
commit 4d09e19
Showing
35 changed files
with
1,907 additions
and
101 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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Reisa | ||
module REIformslive | ||
class Credentials | ||
attr_reader :username, :password | ||
|
||
|
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,105 @@ | ||
module REIformslive | ||
class Form | ||
PATH = '/forms'.freeze | ||
|
||
attr_reader :data | ||
|
||
def initialize data: {} | ||
@data = data | ||
end | ||
|
||
def id | ||
data['id'].to_i | ||
end | ||
|
||
def template_version_id | ||
data['template_version_id'].to_i | ||
end | ||
|
||
def agency_id | ||
data['agency_id'].to_i | ||
end | ||
|
||
def user_id | ||
data['user_id'].to_i | ||
end | ||
|
||
def name | ||
data['name'] | ||
end | ||
|
||
def template? | ||
data['template'].to_s == 'true' | ||
end | ||
|
||
def finalised? | ||
data['finalised'].to_s == 'true' | ||
end | ||
|
||
def private? | ||
data['private'].to_s == 'true' | ||
end | ||
|
||
def created_at | ||
Time.at data['created'].to_i | ||
end | ||
|
||
def updated_at | ||
Time.at data['updated'].to_i | ||
end | ||
|
||
def given_name | ||
data['given_name'] | ||
end | ||
|
||
def surname | ||
data['surname'] | ||
end | ||
|
||
def full_name | ||
"#{given_name} #{surname}" | ||
end | ||
|
||
def template_cost | ||
data['template_cost'].to_i | ||
end | ||
|
||
def template_id | ||
data['template_id'].to_i | ||
end | ||
|
||
def template_name | ||
data['template_name'] | ||
end | ||
|
||
def template_code | ||
data['template_code'] | ||
end | ||
|
||
def template_instruction_pages | ||
data['template_instruction_pages'].to_i | ||
end | ||
|
||
def update data={}, path: "#{PATH}/#{id}/save" | ||
REIformslive::Session | ||
.put(path: path, data: data) | ||
.parse_json['message'] | ||
.send(:==, 'The form has been saved.') | ||
.tap{|ok| @data = self.class.find(id).data if ok } | ||
end | ||
|
||
def self.all path: PATH | ||
REIformslive::Session | ||
.get(path: path) | ||
.parse_json | ||
.map{|data| self.new data: data } | ||
end | ||
|
||
def self.find id, path: "#{PATH}/#{id}" | ||
self.new data: | ||
REIformslive::Session | ||
.get(path: path) | ||
.parse_json | ||
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,27 @@ | ||
module REIformslive | ||
class Session | ||
require 'faraday' | ||
|
||
def self.get path: '/' | ||
connection | ||
.get(path) | ||
.body | ||
end | ||
|
||
def self.put path: '/', data: {} | ||
connection | ||
.put(path, data) | ||
.body | ||
end | ||
|
||
def self.base_url | ||
'https://sa-api.staging.reiformslive.com.au' | ||
end | ||
|
||
def self.connection | ||
conn = Faraday.new base_url | ||
conn.basic_auth '4b66ff95-ade7-413e-b086-0044de7b4ccf', 'ae7e5a1b-e85d-43c4-8d01-fd5cb47d7044' | ||
conn | ||
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
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,93 @@ | ||
module REIformslive | ||
class UserTemplate | ||
PATH = '/user-templates'.freeze | ||
|
||
attr_reader :data | ||
|
||
def initialize data: '{}' | ||
@data = data | ||
end | ||
|
||
def id | ||
data['id'].to_i | ||
end | ||
|
||
def template_version_id | ||
data['template_version_id'].to_i | ||
end | ||
|
||
def agency_id | ||
data['agency_id'].to_i | ||
end | ||
|
||
def user_id | ||
data['user_id'].to_i | ||
end | ||
|
||
def name | ||
data['name'] | ||
end | ||
|
||
def template? | ||
data['template'].to_s == 'true' | ||
end | ||
|
||
def finalised? | ||
data['finalised'].to_s == 'true' | ||
end | ||
|
||
def private? | ||
data['private'].to_s == 'true' | ||
end | ||
|
||
def created_at | ||
Time.at data['created'].to_i | ||
end | ||
|
||
def updated_at | ||
Time.at data['updated'].to_i | ||
end | ||
|
||
def given_name | ||
data['given_name'] | ||
end | ||
|
||
def surname | ||
data['surname'] | ||
end | ||
|
||
def full_name | ||
"#{given_name} #{surname}" | ||
end | ||
|
||
def template_cost | ||
data['template_cost'].to_i | ||
end | ||
|
||
def template_id | ||
data['template_id'].to_i | ||
end | ||
|
||
def original_template_name | ||
data['template_name'] | ||
end | ||
|
||
def original_template_code | ||
data['template_code'] | ||
end | ||
|
||
def self.all | ||
REIformslive::Session | ||
.get(path: PATH) | ||
.parse_json | ||
.map{|data| self.new data: data } | ||
end | ||
|
||
def self.find id | ||
self.new data: | ||
REIformslive::Session | ||
.get(path: "#{PATH}/#{id}") | ||
.parse_json | ||
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Reisa | ||
module REIformslive | ||
VERSION = "0.1.0" | ||
end |
Oops, something went wrong.