method_crm 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/lib/method_crm.rb +39 -11
- data/method_crm.gemspec +5 -3
- data/spec/method_crm_spec.rb +105 -7
- data/spec/spec_helper.rb +16 -1
- metadata +39 -6
data/.gitignore
CHANGED
data/.rspec
ADDED
data/lib/method_crm.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'multi_xml'
|
3
|
+
|
4
|
+
class MethodCrmClientError < StandardError; end
|
3
5
|
module MethodCrm
|
4
6
|
class Client
|
5
7
|
|
@@ -7,27 +9,53 @@ module MethodCrm
|
|
7
9
|
@auth = {strCompanyAccount: company, strLogin: username, strPassword: password, strSessionID: nil}
|
8
10
|
end
|
9
11
|
|
10
|
-
def table_list
|
11
|
-
parsed_response('TableList')
|
12
|
+
def table_list(output = nil)
|
13
|
+
results = parsed_response('TableList')
|
14
|
+
case output.to_s
|
15
|
+
when 'detailed'
|
16
|
+
results
|
17
|
+
else
|
18
|
+
results.map { |table| table['TableName'] }
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
14
|
-
def field_list(table)
|
15
|
-
parsed_response('FieldList', {'strTable' => table})
|
22
|
+
def field_list(table, output = nil)
|
23
|
+
results = parsed_response('FieldList', {'strTable' => table})
|
24
|
+
case output.to_s
|
25
|
+
when 'detailed'
|
26
|
+
results
|
27
|
+
else
|
28
|
+
results.map { |table| table['FieldName'] }
|
29
|
+
end
|
16
30
|
end
|
17
31
|
|
18
|
-
def get_records(table,
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
data = @auth.merge({strTable: table, strFields: fields, strWhereClause: nil, strGroupByClause: nil, strHaving: nil, strOrderBy: nil})
|
32
|
+
def get_records(table, options={})
|
33
|
+
options[:fields] ||= field_list(table).join(',')
|
34
|
+
options = {:where => nil}.merge(options)
|
35
|
+
data = @auth.merge({strTable: table, strFields: options[:fields], strWhereClause: options[:where], strGroupByClause: nil, strHaving: nil, strOrderBy: nil})
|
23
36
|
parsed_response('Select_XML', data)
|
24
37
|
end
|
25
38
|
|
39
|
+
def get_record(table, options={})
|
40
|
+
record = get_records(table, options)
|
41
|
+
raise MethodCrmClientError, 'Query returned more than one record' unless record.is_a?(Hash)
|
42
|
+
record
|
43
|
+
end
|
26
44
|
private
|
27
45
|
def parsed_response(opperation, data={})
|
28
46
|
result = RestClient.post("http://www.methodintegration.com/MethodAPI/service.asmx/MethodAPI#{opperation}V2", @auth.merge(data))
|
29
|
-
|
30
|
-
|
47
|
+
xml = MultiXml.parse(result)
|
48
|
+
content = xml['string']['__content__'] || xml['string']
|
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
|
56
|
+
else
|
57
|
+
raise MethodCrmClientError, parsed_content['MethodAPI']['response']
|
58
|
+
end
|
31
59
|
end
|
32
60
|
end
|
33
61
|
end
|
data/method_crm.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "method_crm"
|
4
|
-
gem.version = '0.0
|
4
|
+
gem.version = '0.1.0'
|
5
5
|
|
6
6
|
gem.author = 'Torey Heinz'
|
7
7
|
gem.email = 'toreyheinz@gmail.com'
|
@@ -15,7 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.add_dependency 'rest-client', '~> 1.6'
|
16
16
|
gem.add_dependency 'multi_xml'
|
17
17
|
|
18
|
-
gem.add_development_dependency 'rake',
|
19
|
-
gem.add_development_dependency 'rspec',
|
18
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 2.12'
|
20
|
+
gem.add_development_dependency 'vcr', '~> 1.6.0'
|
21
|
+
gem.add_development_dependency 'webmock', '~> 1.6.0'
|
20
22
|
gem.test_files = gem.files.grep(/^spec/)
|
21
23
|
end
|
data/spec/method_crm_spec.rb
CHANGED
@@ -1,17 +1,115 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MethodCrm::Client do
|
4
|
-
let(:client) {MethodCrm::Client.new(
|
4
|
+
let(:client) {MethodCrm::Client.new(
|
5
|
+
CONFIG[:company],
|
6
|
+
CONFIG[:user],
|
7
|
+
CONFIG[:password]
|
8
|
+
)}
|
9
|
+
use_vcr_cassette
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
describe '#table_list' do
|
12
|
+
it 'returns a list of table names' do
|
13
|
+
results = client.table_list
|
14
|
+
results.should include(
|
15
|
+
"Account",
|
16
|
+
"AccountAccountType",
|
17
|
+
"VendorCreditLineItem",
|
18
|
+
"VendorType"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
context ":detailed" do
|
23
|
+
it 'returns a list of table details' do
|
24
|
+
results = client.table_list(:detailed)
|
25
|
+
results.first.keys.should include(
|
26
|
+
'TableName',
|
27
|
+
'SupportsAdd',
|
28
|
+
'SupportsEdit'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
end
|
8
32
|
end
|
9
33
|
|
10
|
-
|
11
|
-
|
34
|
+
describe '#field_list' do
|
35
|
+
it 'returns a given table`s field names' do
|
36
|
+
results = client.field_list('AccountAccountType')
|
37
|
+
results.should include("AccountTypeName", "RecordID")
|
38
|
+
end
|
39
|
+
|
40
|
+
context ":detailed" do
|
41
|
+
it 'returns a given table`s field details' do
|
42
|
+
results = client.field_list('AccountAccountType', :detailed)
|
43
|
+
results.first.keys.should include(
|
44
|
+
"SupportsAdd",
|
45
|
+
"SupportsEdit",
|
46
|
+
"IsRequired",
|
47
|
+
"FieldName",
|
48
|
+
"MaxSize",
|
49
|
+
"DataType"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
12
53
|
end
|
13
54
|
|
14
|
-
|
15
|
-
|
55
|
+
describe '#get_records' do
|
56
|
+
it 'returns a given table`s records' do
|
57
|
+
results = client.get_records('AccountAccountType')
|
58
|
+
results.map {|record| record['AccountTypeName'] }.should include(
|
59
|
+
"AccountsPayable",
|
60
|
+
"AccountsReceivable",
|
61
|
+
"Bank",
|
62
|
+
"CostOfGoodsSold",
|
63
|
+
"CreditCard",
|
64
|
+
"Equity",
|
65
|
+
"Expense",
|
66
|
+
"FixedAsset",
|
67
|
+
"Income",
|
68
|
+
"LongTermLiability",
|
69
|
+
"NonPosting",
|
70
|
+
"OtherAsset",
|
71
|
+
"OtherCurrentAsset",
|
72
|
+
"OtherCurrentLiability",
|
73
|
+
"OtherExpense",
|
74
|
+
"OtherIncome",
|
75
|
+
"Suspense"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'limits records with a where clause' do
|
80
|
+
results = client.get_records('AccountAccountType', {:where => "AccountTypeName like 'Other%'"})
|
81
|
+
account_type_names = results.map {|record| record['AccountTypeName'] }
|
82
|
+
account_type_names.should include(
|
83
|
+
"OtherAsset",
|
84
|
+
"OtherCurrentAsset",
|
85
|
+
"OtherCurrentLiability",
|
86
|
+
"OtherExpense",
|
87
|
+
"OtherIncome",
|
88
|
+
)
|
89
|
+
account_type_names.should_not include(
|
90
|
+
"AccountsPayable",
|
91
|
+
"Suspense"
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns an empty Array when no records are found' do
|
96
|
+
results = client.get_records('AccountAccountType', {:where => "AccountTypeName like 'SomeNonExistingName!'"})
|
97
|
+
results.should eq([])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#get_record' do
|
102
|
+
it "returns a single record" do
|
103
|
+
result = client.get_record('AccountAccountType', {:where => "AccountTypeName like 'CostOfGoodsSold'"})
|
104
|
+
result['AccountTypeName'].should eq('CostOfGoodsSold')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "raises an error if more than one record is found" do
|
108
|
+
expect {
|
109
|
+
client.get_record('AccountAccountType',
|
110
|
+
{:where => "AccountTypeName like 'Other%'"}
|
111
|
+
)
|
112
|
+
}.to raise_error(MethodCrmClientError, 'Query returned more than one record')
|
113
|
+
end
|
16
114
|
end
|
17
115
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
1
2
|
require 'method_crm'
|
3
|
+
require 'vcr'
|
4
|
+
|
2
5
|
CONFIG = YAML.load_file(File.expand_path('../support/config.yml', __FILE__))
|
6
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each{|f| require f }
|
7
|
+
|
8
|
+
RSpec.configure do |c|
|
9
|
+
c.extend VCR::RSpec::Macros
|
10
|
+
end
|
3
11
|
|
4
|
-
|
12
|
+
VCR.config do |c|
|
13
|
+
c.default_cassette_options = {
|
14
|
+
:record => :new_episodes,
|
15
|
+
:match_requests_on => [:method, :uri, :body]
|
16
|
+
}
|
17
|
+
c.stub_with :webmock
|
18
|
+
c.cassette_library_dir = 'spec/support/cassettes'
|
19
|
+
end
|
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.0
|
4
|
+
version: 0.1.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
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '2.
|
69
|
+
version: '2.12'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,39 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '2.
|
77
|
+
version: '2.12'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: vcr
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.6.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.6.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.6.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.6.0
|
78
110
|
description: A ruby wrapper for the MethodCRM API
|
79
111
|
email: toreyheinz@gmail.com
|
80
112
|
executables: []
|
@@ -82,6 +114,7 @@ extensions: []
|
|
82
114
|
extra_rdoc_files: []
|
83
115
|
files:
|
84
116
|
- .gitignore
|
117
|
+
- .rspec
|
85
118
|
- Gemfile
|
86
119
|
- LICENSE
|
87
120
|
- README.md
|
@@ -105,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
138
|
version: '0'
|
106
139
|
segments:
|
107
140
|
- 0
|
108
|
-
hash:
|
141
|
+
hash: -2740670062730519801
|
109
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
143
|
none: false
|
111
144
|
requirements:
|
@@ -114,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
147
|
version: '0'
|
115
148
|
segments:
|
116
149
|
- 0
|
117
|
-
hash:
|
150
|
+
hash: -2740670062730519801
|
118
151
|
requirements: []
|
119
152
|
rubyforge_project:
|
120
153
|
rubygems_version: 1.8.24
|