Skip to content

Commit

Permalink
updated gem structure. implmented :all, :find and :update for forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
aussiDavid committed Aug 27, 2017
1 parent aa49381 commit 4d09e19
Show file tree
Hide file tree
Showing 35 changed files with 1,907 additions and 101 deletions.
11 changes: 8 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ gemspec

group :development do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler', require: false
gem 'guard-rspec' , require: false
gem 'guard-bundler' , require: false
end

group :test do
gem 'webmock'
gem 'webmock'
gem 'vcr'
gem 'byebug'
end

group :development, :test do
gem 'awesome_print', require: 'ap'
end
30 changes: 11 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
PATH
remote: .
specs:
reisa-wrapper (0.1.0)
reiformslive-ruby (0.1.0)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
awesome_print (1.8.0)
byebug (9.0.6)
coderay (1.1.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
faraday (0.13.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
formatador (0.2.5)
guard (2.14.1)
Expand All @@ -36,20 +37,15 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (0.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
json (2.1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.12)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
multipart-post (2.0.0)
nenv (0.3.0)
netrc (0.11.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
Expand All @@ -62,10 +58,6 @@ GEM
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
Expand All @@ -84,9 +76,7 @@ GEM
shellany (0.0.1)
slop (3.6.0)
thor (0.19.4)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
vcr (3.0.3)
webmock (3.0.1)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -96,16 +86,18 @@ PLATFORMS
ruby

DEPENDENCIES
awesome_print
bundler (~> 1.13)
byebug
faraday (~> 0.13.1)
guard
guard-bundler
guard-rspec
json
json (~> 2.1.0)
rake (~> 10.0)
reisa-wrapper!
rest-client
reiformslive-ruby!
rspec (~> 3.0)
vcr
webmock

BUNDLED WITH
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Reisa
module REIformslive
class Credentials
attr_reader :username, :password

Expand Down
105 changes: 105 additions & 0 deletions lib/reiformslive/form.rb
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
27 changes: 27 additions & 0 deletions lib/reiformslive/session.rb
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
21 changes: 11 additions & 10 deletions lib/reisa/template.rb → lib/reiformslive/template.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module Reisa
module REIformslive
class Template
PATH = 'templates'.freeze
require 'reiformslive/core_ext'

PATH = '/templates'.freeze

attr_reader :data, :path

def initialize data: '{}'
@data = data.parse_json

@data = data
end

def cost
Expand Down Expand Up @@ -34,17 +35,17 @@ def template_group_id
end

def self.all
Reisa::Session
REIformslive::Session
.get(path: PATH)
.parse_json
.map{|data| data.to_s.gsub '=>', ':' }
.map{|data| Template.new data: data }
.map{|data| self.new data: data }
end

def self.find id
all
.select{|template| template.id == id }
.first
self.new data:
REIformslive::Session
.get(path: "#{PATH}/#{id}")
.parse_json
end
end
end
93 changes: 93 additions & 0 deletions lib/reiformslive/user_template.rb
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
2 changes: 1 addition & 1 deletion lib/reisa/version.rb → lib/reiformslive/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Reisa
module REIformslive
VERSION = "0.1.0"
end
Loading

0 comments on commit 4d09e19

Please sign in to comment.