landslider 0.5.7 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/{CHANGELOG.markdown → HISTORY.md} +4 -0
  2. data/README.md +108 -0
  3. data/VERSION.yml +1 -1
  4. data/bin/generate_api_key.rb +1 -1
  5. data/landslider.gemspec +41 -5
  6. data/lib/landslider/entities/ws_account.rb +32 -0
  7. data/lib/landslider/entities/ws_account_note.rb +13 -0
  8. data/lib/landslider/entities/ws_account_note_search.rb +23 -0
  9. data/lib/landslider/entities/ws_address.rb +17 -0
  10. data/lib/landslider/entities/ws_contact.rb +38 -0
  11. data/lib/landslider/entities/ws_contact_note.rb +13 -0
  12. data/lib/landslider/entities/ws_contact_note_search.rb +23 -0
  13. data/lib/landslider/entities/ws_contact_search.rb +28 -0
  14. data/lib/landslider/entities/ws_employee.rb +23 -0
  15. data/lib/landslider/entities/ws_entity.rb +15 -0
  16. data/lib/landslider/entities/ws_lead.rb +35 -0
  17. data/lib/landslider/entities/ws_lead_contact.rb +14 -0
  18. data/lib/landslider/entities/ws_lead_note.rb +14 -0
  19. data/lib/landslider/entities/ws_lead_note_search.rb +24 -0
  20. data/lib/landslider/entities/ws_lead_search.rb +31 -0
  21. data/lib/landslider/entities/ws_my_list.rb +20 -0
  22. data/lib/landslider/entities/ws_note.rb +21 -0
  23. data/lib/landslider/entities/ws_opportunity.rb +38 -0
  24. data/lib/landslider/entities/ws_opportunity_note.rb +13 -0
  25. data/lib/landslider/entities/ws_opportunity_note_search.rb +23 -0
  26. data/lib/landslider/entities/ws_opportunity_status.rb +17 -0
  27. data/lib/landslider/entities/ws_payment_term.rb +17 -0
  28. data/lib/landslider/entities/ws_pick_list_item.rb +14 -0
  29. data/lib/landslider/entities/ws_primary_entity.rb +11 -0
  30. data/lib/landslider/entities/ws_product.rb +35 -0
  31. data/lib/landslider/entities/ws_product_family.rb +17 -0
  32. data/lib/landslider/entities/ws_product_result.rb +12 -0
  33. data/lib/landslider/entities/ws_record_upsert_result.rb +13 -0
  34. data/lib/landslider/entities/ws_result.rb +16 -0
  35. data/lib/landslider/entities/ws_search.rb +55 -0
  36. data/lib/landslider/entities/ws_search_criterion.rb +121 -0
  37. data/lib/landslider/entities/ws_search_operator.rb +59 -0
  38. data/lib/landslider/entities/ws_selling_process.rb +17 -0
  39. data/lib/landslider/entities/ws_user.rb +10 -0
  40. data/lib/landslider/entities/ws_user_search.rb +20 -0
  41. data/lib/landslider/entities.rb +46 -0
  42. data/lib/landslider.rb +71 -116
  43. data/test/ws_search_test.rb +13 -0
  44. metadata +41 -5
  45. data/README.rdoc +0 -77
data/lib/landslider.rb CHANGED
@@ -1,117 +1,20 @@
1
1
 
2
+ # Landslider is a soap client to the Landslide CRM SOAP-based API
3
+ # Example:
4
+ #
5
+ # require 'landslider'
6
+ # response = Landslider.login('LOGINTOKEN=' + LS_INSTANCE_NAME)
7
+ # response = Landslider.get_accounts(response[:session_id])
8
+ # response[:accounts].each do |account|
9
+ # puts "id: #{account[:account_id]} name: #{account[:account_name]}"
10
+ # end
11
+ #
12
+
2
13
  require 'handsoap'
3
14
 
4
15
  class Landslider < Handsoap::Service
5
16
 
6
- class WsSearch
7
- attr_writer :first_result_position, :total_results_requested, :updated_on
8
- attr_writer :search_criteria
9
-
10
- def initialize
11
- end
12
-
13
- # @param [Handsoap::XmlMason::Node] msg
14
- # @return [Handsoap::XmlMason::Node]
15
- def soapify_for(msg)
16
- msg.add 'firstResultPosition', @first_result_position || DEFAULT_FIRST_RESULT_POSITION
17
- msg.add 'totalResultsRequested', @total_results_requested || DEFAULT_TOTAL_RESULTS_REQUESTED
18
- msg.add 'updatedOn', @updated_on unless @updated_on.nil?
19
- unless @search_criteria.nil?
20
- @search_criteria.soapify_for(msg)
21
- end
22
-
23
- end
24
-
25
- end
26
-
27
- class WsSearchCriterion
28
- attr_reader :field_id, :operator, :query_value
29
-
30
- def initialize(field_id, operator, query_value)
31
- @field_id = field_id
32
- @operator = operator
33
- @query_value = query_value
34
- end
35
-
36
- # @param [Handsoap::XmlMason::Node] msg
37
- # @return [Handsoap::XmlMason::Node]
38
- def soapify_for(msg)
39
- msg.add('searchCriteria') { |crit|
40
- crit.add 'fieldId', @field_id
41
- crit.add 'operator', @operator
42
- crit.add 'queryValue', @query_value unless @query_value.nil?
43
- }
44
- end
45
- end
46
-
47
- class WsAccountNoteSearch < WsSearch
48
- attr_reader :account_id
49
-
50
- def initialize(account_id)
51
- @account_id = account_id
52
- end
53
-
54
- # @param [Handsoap::XmlMason::Node] msg
55
- # @return [Handsoap::XmlMason::Node]
56
- def soapify_for(msg)
57
- msg.add('accountNoteSearch') { |crit|
58
- crit.add 'accountId', @account_id
59
- super(crit)
60
- }
61
- end
62
- end
63
-
64
- class WsContactNoteSearch < WsSearch
65
- attr_reader :contact_id
66
-
67
- def initialize(contact_id)
68
- @contact_id = contact_id
69
- end
70
-
71
- # @param [Handsoap::XmlMason::Node] msg
72
- # @return [Handsoap::XmlMason::Node]
73
- def soapify_for(msg)
74
- msg.add('contactNote') { |crit|
75
- crit.add 'contactId', @contact_id
76
- super(crit)
77
- }
78
- end
79
- end
80
-
81
- class WsLeadNoteSearch < WsSearch
82
- attr_reader :lead_id
83
-
84
- def initialize(lead_id)
85
- @lead_id = lead_id
86
- end
87
-
88
- # @param [Handsoap::XmlMason::Node] msg
89
- # @return [Handsoap::XmlMason::Node]
90
- def soapify_for(msg)
91
- msg.add('leadNote') { |crit|
92
- crit.add 'leadId', @lead_id
93
- super(crit)
94
- }
95
- end
96
-
97
- end
98
-
99
- class WsOpportunityNoteSearch < WsSearch
100
- attr_reader :opportunity_id
101
-
102
- def initialize(opportunity_id)
103
- @opportunity_id = opportunity_id
104
- end
105
-
106
- # @param [Handsoap::XmlMason::Node] msg
107
- # @return [Handsoap::XmlMason::Node]
108
- def soapify_for(msg)
109
- msg.add('opportunityNote') { |crit|
110
- crit.add 'opportunityId', @opportunity_id
111
- super(crit)
112
- }
113
- end
114
- end
17
+ require 'landslider/entities'
115
18
 
116
19
  LS_API_NAMESPACE='http://www.landslide.com/webservices/SoapService'
117
20
  LS_API_ENDPOINT = {
@@ -119,13 +22,14 @@ class Landslider < Handsoap::Service
119
22
  :version => 1
120
23
  }
121
24
 
122
- DEFAULT_FIRST_RESULT_POSITION=1
123
- DEFAULT_TOTAL_RESULTS_REQUESTED=25
25
+ DEFAULT_FIRST_RESULT_POSITION = 1
26
+ DEFAULT_TOTAL_RESULTS_REQUESTED = 25
124
27
 
125
28
  endpoint LS_API_ENDPOINT
126
29
 
127
30
  attr_accessor :session_id
128
31
 
32
+ # @param [Handsoap::XmlMason::Document] doc
129
33
  def on_create_document(doc)
130
34
  doc.alias 'urn', LS_API_NAMESPACE
131
35
  header = doc.find('Header')
@@ -134,17 +38,17 @@ class Landslider < Handsoap::Service
134
38
  }
135
39
  end
136
40
 
41
+ # @param [Handsoap::Http::Request] http_request
137
42
  def on_after_create_http_request(http_request)
138
43
  http_request.headers.merge!({'user-agent' => ['landslider-ruby-gem-version-0.4.6']})
139
-
140
- # TODO: use cookies to maintain session state
141
- # http_request.headers.merge!({'cookie' => ["JSESSIONID=#{self.session_id}"]})
142
44
  end
143
45
 
144
46
  def on_http_error(response)
145
47
  puts response.inspect
146
48
  end
147
49
 
50
+ # @param [String] session_id
51
+ # @return [Hash]
148
52
  def login(session_id)
149
53
  self.session_id = session_id
150
54
  response = invoke('login', :soap_action => :none) do |message|
@@ -158,6 +62,9 @@ class Landslider < Handsoap::Service
158
62
  parse_login_result(node)
159
63
  end
160
64
 
65
+ # @param [WsAccountSearch] search
66
+ # @param [String] session_id
67
+ # @return [Hash]
161
68
  def get_accounts(session_id, search=WsSearch.new)
162
69
  self.session_id = session_id
163
70
  response = invoke('getAccounts', :soap_action => :none) do |message|
@@ -170,6 +77,8 @@ class Landslider < Handsoap::Service
170
77
  parse_get_accounts_result(node)
171
78
  end
172
79
 
80
+ # @param [String] session_id
81
+ # @return [Hash]
173
82
  def get_account_by_id(session_id, account_id)
174
83
  self.session_id = session_id
175
84
 
@@ -181,6 +90,10 @@ class Landslider < Handsoap::Service
181
90
  parse_get_account_by_id_result(node)
182
91
  end
183
92
 
93
+ # @param [String] session_id
94
+ # @param [String] account_id
95
+ # @param [Boolean] is_primary
96
+ # @return [Hash]
184
97
  def get_account_contacts(session_id, account_id, is_primary=false)
185
98
  self.session_id = session_id
186
99
  response = invoke('getAccountContacts', :soap_action => :none) do |message|
@@ -192,12 +105,17 @@ class Landslider < Handsoap::Service
192
105
  parse_get_account_contacts_result(node)
193
106
  end
194
107
 
108
+ # @param [String] session_id
109
+ # @return [Hash]
195
110
  def get_account_custom_fields(session_id)
196
111
  response = invoke('getAccountCustomFields')
197
112
  node = response.document.xpath('//ns:getAccountCustomFieldsResponse', ns)
198
113
  parse_get_entity_custom_fields_result(node)
199
114
  end
200
-
115
+
116
+ # @param [String] session_id
117
+ # @param [WsSearch] search
118
+ # @return [Hash]
201
119
  def get_account_notes(session_id, search)
202
120
  self.session_id = session_id
203
121
 
@@ -207,7 +125,9 @@ class Landslider < Handsoap::Service
207
125
  node = response.document.xpath('//ns:getAccountNotesResponse', ns)
208
126
  parse_get_account_notes_result(node)
209
127
  end
210
-
128
+
129
+ # @param [String] session_id
130
+ # @return [Hash]
211
131
  def get_account_opportunities(session_id, account_id)
212
132
  self.session_id = session_id
213
133
  response = invoke('getAccountOpportunities', :soap_action => :none) do |message|
@@ -218,6 +138,8 @@ class Landslider < Handsoap::Service
218
138
  parse_get_account_opportunities_result(node)
219
139
  end
220
140
 
141
+ # @param [String] session_id
142
+ # @return [Hash]
221
143
  def get_api_version(session_id)
222
144
  self.session_id = session_id
223
145
 
@@ -227,9 +149,14 @@ class Landslider < Handsoap::Service
227
149
  parse_api_version_result(node)
228
150
  end
229
151
 
152
+
153
+ # @param [String] session_id
154
+ # @param [WsContactSearch] search
155
+ # @return [Hash]
230
156
  def get_contacts(session_id, search=WsSearch.new)
231
157
  self.session_id = session_id
232
158
 
159
+ # public WsContactResultSet getContacts(WsContactSearch request)
233
160
  response = invoke('getContacts', :soap_action => :none) do |message|
234
161
  message.add('contactsRequest') { |req|
235
162
  search.soapify_for(req)
@@ -239,6 +166,8 @@ class Landslider < Handsoap::Service
239
166
  parse_get_contacts_result(node)
240
167
  end
241
168
 
169
+ # @param [String] session_id
170
+ # @return [Hash]
242
171
  def get_contact_custom_fields(session_id)
243
172
  self.session_id = session_id
244
173
 
@@ -247,6 +176,9 @@ class Landslider < Handsoap::Service
247
176
  parse_get_entity_custom_fields_result(node)
248
177
  end
249
178
 
179
+ # @param [String] session_id
180
+ # @param [WsSearch] search
181
+ # @return [Hash]
250
182
  def get_contact_notes(session_id, search)
251
183
  self.session_id = session_id
252
184
 
@@ -258,6 +190,9 @@ class Landslider < Handsoap::Service
258
190
 
259
191
  end
260
192
 
193
+ # @param [String] user_id
194
+ # @param [String] session_id
195
+ # @return [Hash]
261
196
  def get_instance_information(session_id, user_id)
262
197
  self.session_id = session_id
263
198
 
@@ -268,6 +203,9 @@ class Landslider < Handsoap::Service
268
203
  parse_get_instance_information_result(node)
269
204
  end
270
205
 
206
+ # @param [String] session_id
207
+ # @param [WsLeadSearch] search
208
+ # @return [Hash]
271
209
  def get_leads(session_id, search=WsSearch.new)
272
210
  self.session_id = session_id
273
211
 
@@ -281,12 +219,17 @@ class Landslider < Handsoap::Service
281
219
  parse_get_leads_result(node)
282
220
  end
283
221
 
222
+ # @param [String] session_id
223
+ # @return [Hash]
284
224
  def get_lead_custom_fields(session_id)
285
225
  response = invoke('getLeadCustomFields')
286
226
  node = response.document.xpath('//ns:getLeadCustomFieldsResponse', ns)
287
227
  parse_get_entity_custom_fields_result(node)
288
228
  end
289
229
 
230
+ # @param [String] session_id
231
+ # @param [WsSearch] search
232
+ # @return [Hash]
290
233
  def get_lead_notes(session_id, search)
291
234
  self.session_id = session_id
292
235
 
@@ -297,6 +240,9 @@ class Landslider < Handsoap::Service
297
240
  parse_get_lead_notes_result(node)
298
241
  end
299
242
 
243
+ # @param [WsOpportunitySearch] search
244
+ # @param [String] session_id
245
+ # @return [Hash]
300
246
  def get_opportunities(session_id, search=WsSearch.new)
301
247
  self.session_id = session_id
302
248
 
@@ -309,6 +255,8 @@ class Landslider < Handsoap::Service
309
255
  parse_get_opportunities_result(node)
310
256
  end
311
257
 
258
+ # @param [String] session_id
259
+ # @return [Hash]
312
260
  def get_opportunity_custom_fields(session_id)
313
261
  self.session_id = session_id
314
262
 
@@ -317,6 +265,9 @@ class Landslider < Handsoap::Service
317
265
  parse_get_entity_custom_fields_result(node)
318
266
  end
319
267
 
268
+ # @param [String] session_id
269
+ # @param [WsSearch] search
270
+ # @return [Hash]
320
271
  def get_opportunity_notes(session_id, search)
321
272
  self.session_id = session_id
322
273
 
@@ -327,6 +278,8 @@ class Landslider < Handsoap::Service
327
278
  parse_get_opportunity_notes_result(node)
328
279
  end
329
280
 
281
+ # @param [String] session_id
282
+ # @return [Hash]
330
283
  def get_user_information(session_id, user_id)
331
284
 
332
285
  self.session_id = session_id
@@ -337,6 +290,8 @@ class Landslider < Handsoap::Service
337
290
  parse_get_user_information_by_id_result(node)
338
291
  end
339
292
 
293
+ # @param [String] session_id
294
+ # @return [Hash]
340
295
  def get_user_information_by_id(session_id, user_id)
341
296
  self.session_id = session_id
342
297
 
@@ -51,5 +51,18 @@ class WsSearchTest < Test::Unit::TestCase
51
51
  assert_equal target_phase_name, result[:opportunities][2][:current_phase_name]
52
52
  end
53
53
 
54
+ def test_ws_search_initialized_with_attrs
55
+ search = Landslider::WsSearch.new
56
+ search.first_result_position = 2
57
+ search.total_results_requested = 4
58
+ assert_equal 2, search.instance_variable_get(:@first_result_position)
59
+ assert_equal 4, search.instance_variable_get(:@total_results_requested)
60
+ end
54
61
 
62
+ def test_ws_search_initialized_with_params
63
+ search = Landslider::WsSearch.new({:first_result_position => 25, :total_results_requested => 50})
64
+ assert_equal 25, search.instance_variable_get(:@first_result_position)
65
+ assert_equal 50, search.instance_variable_get(:@total_results_requested)
66
+ end
67
+
55
68
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: landslider
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.7
5
+ version: 0.5.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jay Prall
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-07 00:00:00 -04:00
13
+ date: 2011-05-11 00:00:00 -04:00
14
14
  default_executable: generate_api_key.rb
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -65,18 +65,54 @@ extensions: []
65
65
 
66
66
  extra_rdoc_files:
67
67
  - LICENSE
68
- - README.rdoc
68
+ - README.md
69
69
  files:
70
- - CHANGELOG.markdown
71
70
  - Gemfile
71
+ - HISTORY.md
72
72
  - LICENSE
73
- - README.rdoc
73
+ - README.md
74
74
  - Rakefile
75
75
  - VERSION.yml
76
76
  - bin/generate_api_key.rb
77
77
  - init.rb
78
78
  - landslider.gemspec
79
79
  - lib/landslider.rb
80
+ - lib/landslider/entities.rb
81
+ - lib/landslider/entities/ws_account.rb
82
+ - lib/landslider/entities/ws_account_note.rb
83
+ - lib/landslider/entities/ws_account_note_search.rb
84
+ - lib/landslider/entities/ws_address.rb
85
+ - lib/landslider/entities/ws_contact.rb
86
+ - lib/landslider/entities/ws_contact_note.rb
87
+ - lib/landslider/entities/ws_contact_note_search.rb
88
+ - lib/landslider/entities/ws_contact_search.rb
89
+ - lib/landslider/entities/ws_employee.rb
90
+ - lib/landslider/entities/ws_entity.rb
91
+ - lib/landslider/entities/ws_lead.rb
92
+ - lib/landslider/entities/ws_lead_contact.rb
93
+ - lib/landslider/entities/ws_lead_note.rb
94
+ - lib/landslider/entities/ws_lead_note_search.rb
95
+ - lib/landslider/entities/ws_lead_search.rb
96
+ - lib/landslider/entities/ws_my_list.rb
97
+ - lib/landslider/entities/ws_note.rb
98
+ - lib/landslider/entities/ws_opportunity.rb
99
+ - lib/landslider/entities/ws_opportunity_note.rb
100
+ - lib/landslider/entities/ws_opportunity_note_search.rb
101
+ - lib/landslider/entities/ws_opportunity_status.rb
102
+ - lib/landslider/entities/ws_payment_term.rb
103
+ - lib/landslider/entities/ws_pick_list_item.rb
104
+ - lib/landslider/entities/ws_primary_entity.rb
105
+ - lib/landslider/entities/ws_product.rb
106
+ - lib/landslider/entities/ws_product_family.rb
107
+ - lib/landslider/entities/ws_product_result.rb
108
+ - lib/landslider/entities/ws_record_upsert_result.rb
109
+ - lib/landslider/entities/ws_result.rb
110
+ - lib/landslider/entities/ws_search.rb
111
+ - lib/landslider/entities/ws_search_criterion.rb
112
+ - lib/landslider/entities/ws_search_operator.rb
113
+ - lib/landslider/entities/ws_selling_process.rb
114
+ - lib/landslider/entities/ws_user.rb
115
+ - lib/landslider/entities/ws_user_search.rb
80
116
  - test/landslider_test.rb
81
117
  - test/test_helper.rb
82
118
  - test/ws_account_note_search_test.rb
data/README.rdoc DELETED
@@ -1,77 +0,0 @@
1
- = Landslider
2
-
3
- Ruby interface to Landslide's SOAP based API
4
-
5
- == Pre-requisites
6
-
7
- == Dependencies
8
-
9
- === Landslide account
10
-
11
- An account with Landslide that has the API enabled. (www.landslide.com) Contact support@landslide.com to have the API enabled.
12
-
13
- === Ruby gem dependencies
14
-
15
- gem install jeweler curb handsoap
16
-
17
- == Installation
18
-
19
- gem install landslider
20
-
21
- == Usage
22
-
23
-
24
- Configuration:
25
-
26
- # constants to be set by rails environment config files
27
-
28
- LS_INSTANCE_NAME = 'jaytest'
29
- LS_API_USERNAME = 'jayp@landslide.com'
30
-
31
- # see bin/generate_api_key.rb for details on how to generate this key
32
- LS_API_KEY = '53308ccbdcb7f23fbd81a0b2ebcf12a4'
33
-
34
- require 'landslider'
35
- response = Landslider.login('LOGINTOKEN=' + LS_INSTANCE_NAME)
36
- response = Landslider.get_accounts(response[:session_id])
37
- response[:accounts].each do |account|
38
- puts "id: #{account[:account_id]} name: #{account[:account_name]}"
39
- end
40
-
41
- == Testing
42
-
43
- The default rake task is set to run the tests.
44
-
45
- $ rake
46
-
47
- Tests are needed here because the API uses a specific XML structure for requests and responses.
48
-
49
- == Contributing
50
-
51
- Read the github doc on forking:
52
- http://help.github.com/forking/
53
-
54
- == API methods
55
-
56
- These are the api methods that can be called. There are plenty of others to map out.
57
-
58
- * login
59
- * getApiVersion
60
- * getAccounts
61
- * getAccountById
62
- * getAccountCustomFields
63
- * getAccountContacts
64
- * getAccountNotes
65
- * getAccountOpportunities
66
- * getContacts
67
- * getContactCustomFields
68
- * getContactNotes
69
- * getInstanceInformation
70
- * getLeads
71
- * getLeadCustomFields
72
- * getLeadNotes
73
- * getOpportunities
74
- * getOpportunityCustomFields
75
- * getOpportunityNotes
76
- * getUserInformation
77
- * getUserInformationById