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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68ac46ac359aa92559aba1978421b651cef0c689
4
- data.tar.gz: 2e271efa19715d2a236f0e052b8ec8e94d0c7417
3
+ metadata.gz: d6d2d523b28059cb548e7681f1f2ec0765121470
4
+ data.tar.gz: 2994bc44e356d9f7a00dad0d04e83354763b4ca8
5
5
  SHA512:
6
- metadata.gz: 43098e427e3c46cbbd2a9fbc50517566f1542f5a55056b9c3626921fb5a2495dc6494326ef3608f80c926fc9694f91b3543864bab49ba77b543ac53725db92f8
7
- data.tar.gz: 9c1465885322b7696f70da26ad0ec1074dc31f99982a19d4755ae0839428593b0ffe0f70b39493f1d7ea87f50388cf8fcc90814c1d3428cae106bc4e79a6ace8
6
+ metadata.gz: 060aca0059fe895b85139c1d8dc33a04e6eb49c0fa88f518c2e522b0291edcc942f961f4fbb872d8ac1c5ef68c3e920dbec747d9c498ef2f23551c076f698464
7
+ data.tar.gz: ae995236a9f669b16fc048e98d8499a4c010184ea4fec23dd2da00b470b26ea6b530048af553028279f567102e2706d369d7492892fcb0d776248012abef6b52
@@ -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 initialize(connection, attrs)
15
- super
16
- @company_id ||= SecureRandom.hex(12)
17
- @status ||= 'Active'
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
@@ -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(transform(attrs))
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 = resp.nil? ? [] : remove_root_node(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)
@@ -34,5 +34,11 @@ module Connectwise
34
34
  attrs[:opportunity_name] = name if name
35
35
  attrs
36
36
  end
37
+
38
+ def self.where_transform(attrs)
39
+ name = attrs.delete(:name) || attrs.delete(:opportunity_name)
40
+ attrs[:opportunity_name] = name if name
41
+ attrs
42
+ end
37
43
  end
38
44
  end
@@ -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, {SrServiceRecid: id}))
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, {SrServiceRecid: id}
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
@@ -1,3 +1,3 @@
1
1
  module Connectwise
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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', focus:true do
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 = found_tickets.first.destroy
48
+ deleted_ticket = found_ticket.destroy
50
49
  expect(deleted_ticket).not_to be_nil
51
- found_ticket = Connectwise::ticket.find(conn, new_ticket.id)
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.5
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-20 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler