method_crm 0.1.0 → 0.2.0
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.
- data/lib/core_ext/hash.rb +21 -0
- data/lib/core_ext/string.rb +9 -0
- data/lib/method_crm.rb +26 -25
- data/method_crm.gemspec +1 -1
- data/spec/method_crm_spec.rb +20 -14
- metadata +6 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Hash
|
|
2
|
+
def rubyize_keys
|
|
3
|
+
convert_hash_keys(self)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
private
|
|
7
|
+
def convert_hash_keys(value)
|
|
8
|
+
case value
|
|
9
|
+
when Hash
|
|
10
|
+
Hash[value.map { |k, v| [rubyize_key(k), convert_hash_keys(v)] }]
|
|
11
|
+
when Array
|
|
12
|
+
value.map { |v| convert_hash_keys(v) }
|
|
13
|
+
else
|
|
14
|
+
value
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def rubyize_key(key)
|
|
19
|
+
key.to_s.underscore.sub(/class/, 'klass').to_sym
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/method_crm.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require 'rest_client'
|
|
2
2
|
require 'multi_xml'
|
|
3
|
+
require 'core_ext/string'
|
|
4
|
+
require 'core_ext/hash'
|
|
3
5
|
|
|
4
6
|
class MethodCrmClientError < StandardError; end
|
|
5
7
|
module MethodCrm
|
|
@@ -9,53 +11,52 @@ module MethodCrm
|
|
|
9
11
|
@auth = {strCompanyAccount: company, strLogin: username, strPassword: password, strSessionID: nil}
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def table_list(
|
|
13
|
-
results =
|
|
14
|
-
case output.to_s
|
|
14
|
+
def table_list(options={})
|
|
15
|
+
results = perform_opperation('TableList')
|
|
16
|
+
case options[:output].to_s
|
|
15
17
|
when 'detailed'
|
|
16
18
|
results
|
|
17
19
|
else
|
|
18
|
-
results.map { |table| table[
|
|
20
|
+
results.map { |table| table[:table_name] }
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
def field_list(table,
|
|
23
|
-
results =
|
|
24
|
-
case output.to_s
|
|
24
|
+
def field_list(table, options={})
|
|
25
|
+
results = perform_opperation('FieldList', {'strTable' => table})
|
|
26
|
+
case options[:output].to_s
|
|
25
27
|
when 'detailed'
|
|
26
28
|
results
|
|
27
29
|
else
|
|
28
|
-
results.map { |table| table[
|
|
30
|
+
results.map { |table| table[:field_name] }
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def get_records(table, options={})
|
|
33
35
|
options[:fields] ||= field_list(table).join(',')
|
|
34
|
-
options = {:where => nil}.merge(options)
|
|
35
36
|
data = @auth.merge({strTable: table, strFields: options[:fields], strWhereClause: options[:where], strGroupByClause: nil, strHaving: nil, strOrderBy: nil})
|
|
36
|
-
|
|
37
|
+
perform_opperation('Select_XML', data)
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def get_record(table, options={})
|
|
40
|
-
|
|
41
|
-
raise MethodCrmClientError, 'Query returned more than one record'
|
|
42
|
-
|
|
41
|
+
records = get_records(table, options)
|
|
42
|
+
raise MethodCrmClientError, 'Query returned more than one record' if records.length > 1
|
|
43
|
+
records.first
|
|
43
44
|
end
|
|
45
|
+
|
|
44
46
|
private
|
|
45
|
-
def
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
parsed_content = MultiXml.parse(content)
|
|
50
|
-
if parsed_content['MethodAPI']['response'] == "Success"
|
|
51
|
-
unless parsed_content['MethodAPI']['MethodIntegration'].nil?
|
|
52
|
-
parsed_content['MethodAPI']['MethodIntegration']['Record']
|
|
53
|
-
else
|
|
54
|
-
[]
|
|
55
|
-
end
|
|
47
|
+
def perform_opperation(opperation, data={})
|
|
48
|
+
results = extract_results RestClient.post("http://www.methodintegration.com/MethodAPI/service.asmx/MethodAPI#{opperation}V2", @auth.merge(data))
|
|
49
|
+
if results[:response] == "Success"
|
|
50
|
+
results[:method_integration].nil? ? [] : [results[:method_integration][:record]].flatten
|
|
56
51
|
else
|
|
57
|
-
raise MethodCrmClientError,
|
|
52
|
+
raise MethodCrmClientError, results[:response]
|
|
58
53
|
end
|
|
59
54
|
end
|
|
55
|
+
|
|
56
|
+
def extract_results(response)
|
|
57
|
+
results = MultiXml.parse(response)['string']['__content__'] || xml['string']
|
|
58
|
+
results = MultiXml.parse(results).rubyize_keys
|
|
59
|
+
results[:method_api]
|
|
60
|
+
end
|
|
60
61
|
end
|
|
61
62
|
end
|
data/method_crm.gemspec
CHANGED
data/spec/method_crm_spec.rb
CHANGED
|
@@ -21,11 +21,11 @@ describe MethodCrm::Client do
|
|
|
21
21
|
|
|
22
22
|
context ":detailed" do
|
|
23
23
|
it 'returns a list of table details' do
|
|
24
|
-
results = client.table_list(:detailed)
|
|
24
|
+
results = client.table_list(:output => :detailed)
|
|
25
25
|
results.first.keys.should include(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
:table_name,
|
|
27
|
+
:supports_add,
|
|
28
|
+
:supports_edit
|
|
29
29
|
)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -39,14 +39,14 @@ describe MethodCrm::Client do
|
|
|
39
39
|
|
|
40
40
|
context ":detailed" do
|
|
41
41
|
it 'returns a given table`s field details' do
|
|
42
|
-
results = client.field_list('AccountAccountType', :detailed)
|
|
42
|
+
results = client.field_list('AccountAccountType', :output => :detailed)
|
|
43
43
|
results.first.keys.should include(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
:supports_add,
|
|
45
|
+
:supports_edit,
|
|
46
|
+
:is_required,
|
|
47
|
+
:field_name,
|
|
48
|
+
:max_size,
|
|
49
|
+
:data_type
|
|
50
50
|
)
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -55,7 +55,7 @@ describe MethodCrm::Client do
|
|
|
55
55
|
describe '#get_records' do
|
|
56
56
|
it 'returns a given table`s records' do
|
|
57
57
|
results = client.get_records('AccountAccountType')
|
|
58
|
-
results.map {|record| record[
|
|
58
|
+
results.map {|record| record[:account_type_name] }.should include(
|
|
59
59
|
"AccountsPayable",
|
|
60
60
|
"AccountsReceivable",
|
|
61
61
|
"Bank",
|
|
@@ -78,7 +78,7 @@ describe MethodCrm::Client do
|
|
|
78
78
|
|
|
79
79
|
it 'limits records with a where clause' do
|
|
80
80
|
results = client.get_records('AccountAccountType', {:where => "AccountTypeName like 'Other%'"})
|
|
81
|
-
account_type_names = results.map {|record| record[
|
|
81
|
+
account_type_names = results.map {|record| record[:account_type_name] }
|
|
82
82
|
account_type_names.should include(
|
|
83
83
|
"OtherAsset",
|
|
84
84
|
"OtherCurrentAsset",
|
|
@@ -96,12 +96,18 @@ describe MethodCrm::Client do
|
|
|
96
96
|
results = client.get_records('AccountAccountType', {:where => "AccountTypeName like 'SomeNonExistingName!'"})
|
|
97
97
|
results.should eq([])
|
|
98
98
|
end
|
|
99
|
+
|
|
100
|
+
it 'returns an Array when one record is found' do
|
|
101
|
+
results = client.get_records('AccountAccountType', {:where => "AccountTypeName like 'CostOfGoodsSold'"})
|
|
102
|
+
results.should be_an Array
|
|
103
|
+
results.length.should eq(1)
|
|
104
|
+
end
|
|
99
105
|
end
|
|
100
106
|
|
|
101
107
|
describe '#get_record' do
|
|
102
108
|
it "returns a single record" do
|
|
103
109
|
result = client.get_record('AccountAccountType', {:where => "AccountTypeName like 'CostOfGoodsSold'"})
|
|
104
|
-
result[
|
|
110
|
+
result[:account_type_name].should eq('CostOfGoodsSold')
|
|
105
111
|
end
|
|
106
112
|
|
|
107
113
|
it "raises an error if more than one record is found" do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: method_crm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-12-
|
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rest-client
|
|
@@ -119,6 +119,8 @@ files:
|
|
|
119
119
|
- LICENSE
|
|
120
120
|
- README.md
|
|
121
121
|
- Rakefile
|
|
122
|
+
- lib/core_ext/hash.rb
|
|
123
|
+
- lib/core_ext/string.rb
|
|
122
124
|
- lib/method_crm.rb
|
|
123
125
|
- method_crm.gemspec
|
|
124
126
|
- spec/method_crm_spec.rb
|
|
@@ -138,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
138
140
|
version: '0'
|
|
139
141
|
segments:
|
|
140
142
|
- 0
|
|
141
|
-
hash: -
|
|
143
|
+
hash: -1409876194590315138
|
|
142
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
none: false
|
|
144
146
|
requirements:
|
|
@@ -147,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
149
|
version: '0'
|
|
148
150
|
segments:
|
|
149
151
|
- 0
|
|
150
|
-
hash: -
|
|
152
|
+
hash: -1409876194590315138
|
|
151
153
|
requirements: []
|
|
152
154
|
rubyforge_project:
|
|
153
155
|
rubygems_version: 1.8.24
|