connectwise_sdk 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/connectwise/company.rb +15 -4
- data/lib/connectwise/model.rb +11 -4
- data/lib/connectwise/opportunity.rb +6 -0
- data/lib/connectwise/ticket.rb +7 -2
- data/lib/connectwise/version.rb +1 -1
- data/spec/lib/connectwise/company_spec.rb +8 -1
- data/spec/lib/connectwise/ticket_spec.rb +2 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d2d523b28059cb548e7681f1f2ec0765121470
|
4
|
+
data.tar.gz: 2994bc44e356d9f7a00dad0d04e83354763b4ca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 060aca0059fe895b85139c1d8dc33a04e6eb49c0fa88f518c2e522b0291edcc942f961f4fbb872d8ac1c5ef68c3e920dbec747d9c498ef2f23551c076f698464
|
7
|
+
data.tar.gz: ae995236a9f669b16fc048e98d8499a4c010184ea4fec23dd2da00b470b26ea6b530048af553028279f567102e2706d369d7492892fcb0d776248012abef6b52
|
data/lib/connectwise/company.rb
CHANGED
@@ -6,15 +6,26 @@ module Connectwise
|
|
6
6
|
plural :companies
|
7
7
|
attr_accessor :id, :status, :type, :market, :territory, :web_site, :fax_number, :phone_number, :company_name, :company_id
|
8
8
|
|
9
|
+
def self.where_transform(attrs)
|
10
|
+
attrs[:company_name] ||= attrs.delete(:name) if attrs[:name]
|
11
|
+
attrs
|
12
|
+
end
|
13
|
+
|
9
14
|
def self.transform(attrs)
|
10
15
|
attrs[:company_name] ||= attrs.delete(:name)
|
16
|
+
attrs[:status] ||= 'Active'
|
17
|
+
attrs[:company_id] ||= SecureRandom.hex(12)
|
11
18
|
attrs
|
12
19
|
end
|
13
20
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
def self.find_transform(attrs)
|
22
|
+
attrs[:id] ||= attrs.delete(:company_rec_id)
|
23
|
+
attrs
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.save_transform(attrs)
|
27
|
+
attrs[:id] ||= attrs.delete(:company_rec_id)
|
28
|
+
attrs
|
18
29
|
end
|
19
30
|
|
20
31
|
def to_cw_h
|
data/lib/connectwise/model.rb
CHANGED
@@ -2,11 +2,9 @@ module Connectwise
|
|
2
2
|
module Model
|
3
3
|
module ClassMethods
|
4
4
|
def where(connection, *args, **attrs)
|
5
|
-
conditions = attrs.empty? ? args.join(' ') : attrs_to_query(
|
5
|
+
conditions = attrs.empty? ? args.join(' ') : attrs_to_query(where_transform(attrs))
|
6
6
|
resp = connection.call cw_api_name, "find_#{plural_class_name}".to_sym, {conditions: conditions}
|
7
|
-
resp
|
8
|
-
resp = resp.respond_to?(:to_ary) ? resp : [resp]
|
9
|
-
resp.map {|attrs| self.new(connection, find_transform(attrs)) }
|
7
|
+
normalize_find_response(resp).map {|attrs| self.new(connection, find_transform(attrs)) }
|
10
8
|
end
|
11
9
|
|
12
10
|
def find(connection, id)
|
@@ -40,6 +38,10 @@ module Connectwise
|
|
40
38
|
@plural_form ||= "#{base_class_name.downcase}#{ending}"
|
41
39
|
end
|
42
40
|
|
41
|
+
def where_transform(attrs)
|
42
|
+
attrs
|
43
|
+
end
|
44
|
+
|
43
45
|
def find_transform(attrs)
|
44
46
|
attrs
|
45
47
|
end
|
@@ -64,6 +66,11 @@ module Connectwise
|
|
64
66
|
def remove_root_node(resp)
|
65
67
|
resp.values.first
|
66
68
|
end
|
69
|
+
|
70
|
+
def normalize_find_response(resp)
|
71
|
+
resp = resp.nil? ? [] : remove_root_node(resp)
|
72
|
+
resp.respond_to?(:to_ary) ? resp : [resp]
|
73
|
+
end
|
67
74
|
end
|
68
75
|
|
69
76
|
def self.included(klass)
|
data/lib/connectwise/ticket.rb
CHANGED
@@ -7,7 +7,7 @@ module Connectwise
|
|
7
7
|
#TODO - The use of SrServiceRecid and TicketNumber instead of id - may want to configure these
|
8
8
|
# but this is so inconsistent for tickets that it may not be worth it unless other calls do the same thing
|
9
9
|
def self.find(connection, id)
|
10
|
-
if (attrs = connection.call(cw_api_name, "get_#{cw_api_name}".to_sym, {
|
10
|
+
if (attrs = connection.call(cw_api_name, "get_#{cw_api_name}".to_sym, {ticketNumber: id}))
|
11
11
|
self.new(connection, find_transform(attrs))
|
12
12
|
else
|
13
13
|
fail RecordNotFound
|
@@ -32,11 +32,16 @@ module Connectwise
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def destroy
|
35
|
-
connection.call self.class.cw_api_name, "delete_#{self.class.cw_api_name}".to_sym, {
|
35
|
+
connection.call self.class.cw_api_name, "delete_#{self.class.cw_api_name}".to_sym, {ticketNumber: id}
|
36
36
|
self
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
|
+
def self.find_transform(attrs)
|
41
|
+
attrs[:id] = attrs.delete(:ticket_number)
|
42
|
+
attrs
|
43
|
+
end
|
44
|
+
|
40
45
|
def self.save_transform(attrs)
|
41
46
|
attrs[:id] = attrs.delete(:ticket_number)
|
42
47
|
attrs
|
data/lib/connectwise/version.rb
CHANGED
@@ -25,13 +25,20 @@ describe Connectwise::Company do
|
|
25
25
|
expect(instance).to eq new_company
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'deletes a company based on where data' do
|
29
|
+
new_company = subject.save
|
30
|
+
company = Connectwise::Company.where(conn, company_id: new_company.company_id)
|
31
|
+
instance = company.first.destroy
|
32
|
+
expect {Connectwise::Company.find(conn, instance.id) }.to raise_error Connectwise::RecordNotFound
|
33
|
+
end
|
34
|
+
|
28
35
|
it 'finds a company with search' do
|
29
36
|
subject.save
|
30
37
|
resp = Connectwise::Company.where(conn, company_name: 'Blue Sun')
|
31
38
|
expect(resp).not_to be_empty
|
32
39
|
end
|
33
40
|
|
34
|
-
it 'finds a company with id'
|
41
|
+
it 'finds a company with id' do
|
35
42
|
new_company = subject.save
|
36
43
|
resp = Connectwise::Company.find(conn, new_company.id)
|
37
44
|
expect(resp).not_to be_nil
|
@@ -31,7 +31,6 @@ describe Connectwise::Ticket do
|
|
31
31
|
it 'finds a ticket with id' do
|
32
32
|
subject.company = company.save
|
33
33
|
new_ticket = subject.save
|
34
|
-
p new_ticket.id
|
35
34
|
resp = Connectwise::Ticket.find(conn, new_ticket.id)
|
36
35
|
expect(resp).not_to be_nil
|
37
36
|
expect(resp.id).to eq new_ticket.id
|
@@ -46,9 +45,8 @@ describe Connectwise::Ticket do
|
|
46
45
|
new_ticket = subject.save
|
47
46
|
found_ticket = Connectwise::Ticket.find(conn, new_ticket.id)
|
48
47
|
expect(found_ticket).not_to be_nil
|
49
|
-
deleted_ticket =
|
48
|
+
deleted_ticket = found_ticket.destroy
|
50
49
|
expect(deleted_ticket).not_to be_nil
|
51
|
-
|
52
|
-
expect(found_ticket).to be_nil
|
50
|
+
expect {Connectwise::Ticket.find(conn, new_ticket.id)}.to raise_error Connectwise::RecordNotFound
|
53
51
|
end
|
54
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connectwise_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emery A. Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|