memotoo 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ rvm use 1.8.7@memotoo
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
- gem "savon"
6
- #, "~> 0.9.2"
4
+ gem "i18n"
5
+ gem "activesupport", ">= 2.3.5"
6
+ gem "savon", "~> 0.9.2"
7
7
 
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
@@ -1,6 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ activesupport (3.0.8)
4
5
  builder (3.0.0)
5
6
  git (1.2.5)
6
7
  gyoku (0.4.3)
@@ -8,6 +9,7 @@ GEM
8
9
  httpi (0.9.3)
9
10
  ntlm-http (>= 0.1.1)
10
11
  rack
12
+ i18n (0.6.0)
11
13
  jeweler (1.5.2)
12
14
  bundler (~> 1.0.0)
13
15
  git (>= 1.2.5)
@@ -30,9 +32,11 @@ PLATFORMS
30
32
  ruby
31
33
 
32
34
  DEPENDENCIES
35
+ activesupport (>= 2.3.5)
33
36
  bundler (~> 1.0.0)
37
+ i18n
34
38
  jeweler (~> 1.5.2)
35
39
  rack (~> 1.1.2)
36
40
  rcov
37
- savon
41
+ savon (~> 0.9.2)
38
42
  shoulda
@@ -35,7 +35,7 @@ get a contact from id:
35
35
 
36
36
  search for contacts:
37
37
 
38
- @response = @connect.searchContact("ka")
38
+ @response = @connect.searchContact({:search=>"ka"})
39
39
 
40
40
  modify a contact:
41
41
 
@@ -44,18 +44,30 @@ modify a contact:
44
44
  get contact modified after a date
45
45
 
46
46
  @response = @connect.getContactSync("2011-01-01 10:00:00")
47
+
48
+ playing with contactgroups
49
+
50
+ @connect.addContactGroup({:name=>"Testgroup"})
51
+
52
+ @connect.searchContactGroup({:search=>"ka", :limit_nb=>50})
53
+
54
+ @connect.getContactGroup(12345)
55
+
56
+ @connect.getContactGroupSync("2010-02-23 10:00:00")
57
+
58
+ @connect.deleteContactGroup(12345)
47
59
 
48
60
 
49
61
  ==Testing
50
62
 
51
- I added tests for all possible functions. (rcov 100%)
63
+ I added tests for all implemented functions. (rcov 100%)
52
64
  You can add your own credential to /test/test_memotoo.rb
53
65
 
54
66
  I also added support for {http://test.rubygems.org}[http://test.rubygems.org]
55
67
 
56
68
  You can now use the gem rubygems-test for easy testing this gem.
57
69
 
58
- See my testresult here: http://test.rubygems.org/gems/memotoo/v/1.0.1/test_results/1645
70
+ See my testresult here: http://test.rubygems.org/gems/memotoo/v/1.0.5/test_results/1650
59
71
 
60
72
  ==Documentation
61
73
 
@@ -63,8 +75,8 @@ see rdoc
63
75
 
64
76
  ==To-Dos
65
77
 
66
- 1. Exception handling should be done
67
- 2. I only implemented contacts - these soap-objects are missing: bookmark, bookmark's folder, contact's group, event, holiday, task, note
78
+ 1. Exception handling should be done - fetched problem are written to console
79
+ 2. I only implemented contacts and contact's group - these soap-objects are missing: bookmark, bookmark's folder, event, holiday, task, note
68
80
 
69
81
  It would be nice if *someone* could help me with the missing parts .
70
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
@@ -1,4 +1,7 @@
1
1
  require "memotoo/connect"
2
+ require 'rubygems'
3
+ require 'active_support/inflector'
4
+
2
5
 
3
6
  module Memotoo
4
7
 
@@ -1,6 +1,8 @@
1
1
  require "savon"
2
2
  require "memotoo/core-ext/hash"
3
+ require "memotoo/core-ext/kernel"
3
4
  require "memotoo/contact/contact"
5
+ require "memotoo/contact/contact_group"
4
6
 
5
7
  module Memotoo
6
8
 
@@ -13,6 +15,8 @@ module Memotoo
13
15
 
14
16
  # will hold username and password in a hash style (used for all requests)
15
17
  attr_accessor :opts
18
+
19
+ SEARCHDEFAULTS = { :limit_start => '0', :limit_nb => '100' }
16
20
 
17
21
  #[https] default:true for the SOAP service.
18
22
  # example: @connect=Memotoo::Connect.new("myusername","mypassword")
@@ -33,26 +37,52 @@ module Memotoo
33
37
  # Creates the <tt>Savon::Client</tt>.
34
38
  def client(https=true)
35
39
  #--
36
- # TODO: dont fetch wdsl-file - make setting by myself - it's faster
37
- # # Directly accessing a SOAP endpoint
38
- # client = Savon::Client.new do
39
- # wsdl.endpoint = "http://example.com/UserService"
40
- # wsdl.namespace = "http://users.example.com"
41
- # end
40
+ # in any case problems switch back to receiving the wsdl file from memotoo
41
+ # https: wsdl.document = "https://www.memotoo.com/SOAP-server.php?wsdl"
42
+ # http: wsdl.document = "http://www.memotoo.com/SOAP-server.php?wsdl"
42
43
  #++
43
-
44
- @client ||= Savon::Client.new do
44
+
45
+ @client ||= Savon::Client.new do
46
+ wsdl.namespace="urn:memotooSoap"
45
47
  if https
46
- wsdl.document = "https://www.memotoo.com/SOAP-server.php?wsdl"
48
+ wsdl.endpoint="https://www.memotoo.com/SOAP-server.php"
47
49
  http.auth.ssl.verify_mode = :none
48
50
  else
49
- wsdl.document = "https://www.memotoo.com/SOAP-server.php?wsdl"
51
+ wsdl.endpoint="http://www.memotoo.com/SOAP-server.php"
50
52
  end
51
53
  http.auth.basic self.opts[:param][:login], self.opts[:param][:password]
52
54
  end
53
-
54
55
  end
55
56
 
57
+
58
+ def searchApiCall(searchparameter)
59
+ search = SEARCHDEFAULTS.merge!(searchparameter)
60
+ apicall(calling_method.to_sym, search)
61
+ end
62
+
63
+ def getApiCall(id)
64
+ apicall(calling_method.to_sym, { :id => id })
65
+ end
66
+
67
+ def getSyncApiCall(datetime)
68
+ date2time=Time.mktime(*ParseDate.parsedate(datetime))
69
+ formated_date=date2time.strftime("%Y-%m-%d %H:%M:%S")
70
+ apicall(calling_method.to_sym, { :date => formated_date })
71
+ end
72
+
73
+ def deleteApiCall(id)
74
+ apicall(calling_method.to_sym, { :id => id })
75
+ end
76
+
77
+ def modifyApiCall(details)
78
+ apicall(calling_method.to_sym, details )
79
+ end
80
+
81
+ def addApiCall(details)
82
+ apicall(calling_method.to_sym, details )
83
+ end
84
+
85
+
56
86
  # used internally for a request
57
87
  def apicall(action, parameter)
58
88
 
@@ -75,23 +105,137 @@ module Memotoo
75
105
  end
76
106
  end
77
107
 
108
+ def format_result(response, *_keys_)
109
+ output_key = [(calling_method.underscore+"_response").to_sym] | _keys_
110
+ response.nil? ? nil : response.to_hash.seek(output_key)
111
+ end
112
+
113
+
114
+
115
+ private
116
+
117
+ def go_home(message)
118
+ #--
119
+ # TODO: raising errors instead of writing to STDOUT
120
+ #++
121
+ puts "missing fields: " + message.to_s
122
+ false
123
+ end
124
+
125
+ def has_needed_fields(thehash, *args)
126
+ valid=true
127
+ retarr=[]
128
+ args.each do |arg_item|
129
+ unless thehash.has_key?(arg_item)
130
+ valid = false
131
+ retarr << arg_item
132
+ end
133
+ end
134
+ valid ? true : go_home(retarr.join(", "))
135
+ end
136
+
137
+ def has_needed_search_parameter(searchparameter)
138
+ has_needed_fields(searchparameter, :search)
139
+ end
78
140
 
79
141
  end # class
80
142
 
81
143
  end # module
82
144
 
83
- # stop savon logging and raising errors
145
+ # stop savon logging
84
146
 
85
147
  module Savon
86
148
  module Global
87
-
88
149
  def log?
89
150
  false
90
151
  end
91
-
92
152
  def raise_errors?
93
153
  @raise_errors = true
94
154
  end
95
155
 
96
156
  end
97
157
  end
158
+
159
+ #-- available memotoo soap actions !!!!!!!!!!
160
+
161
+ #event
162
+
163
+ #:get_event,
164
+ #:delete_event,
165
+ #:get_event_sync,
166
+ #:modify_event,
167
+ #:search_event,
168
+ #:add_event,
169
+
170
+ #calendar_category
171
+
172
+ #:search_calendar_category,
173
+ #:add_calendar_category,
174
+ #:delete_calendar_category,
175
+ #:get_calendar_category,
176
+ #:modify_calendar_category,
177
+ #:get_calendar_category_sync,
178
+
179
+ #holiday
180
+
181
+ #:get_holiday,
182
+ #:delete_holiday,
183
+ #:get_holiday_sync,
184
+ #:modify_holiday,
185
+ #:search_holiday,
186
+ #:add_holiday,
187
+ #
188
+
189
+ #contact - ready implemented
190
+ #:add_contact,
191
+ #:modify_contact,
192
+ #:search_contact,
193
+ #:delete_contact,
194
+ #:get_contact_sync,
195
+ #:get_contact,
196
+
197
+ #contact-group - ready implemented
198
+ #
199
+ #:search_contact_group,
200
+ #:add_contact_group,
201
+ #:delete_contact_group,
202
+ #:get_contact_group,
203
+ #:get_contact_group_sync
204
+ #:modify_contact_group
205
+ #
206
+ #bookmark
207
+ #
208
+ #:get_bookmark,
209
+ #:modify_bookmark,
210
+ #:search_bookmark
211
+ #:add_bookmark,
212
+ #:delete_bookmark,
213
+ #:get_bookmark_sync,
214
+ #
215
+ #bookmarkfolder
216
+ #
217
+ #:search_bookmark_folder,
218
+ #:add_bookmark_folder,
219
+ #:delete_bookmark_folder,
220
+ #:get_bookmark_folder,
221
+ #:get_bookmark_folder_sync,
222
+ #:modify_bookmark_folder,
223
+
224
+ #task
225
+
226
+ #:modify_task,
227
+ #:get_task,
228
+ #:get_task_sync,
229
+ #:search_task,
230
+ #:add_task,
231
+ #:delete_task,
232
+
233
+ #note
234
+
235
+ #:get_note_sync
236
+ #:modify_note,
237
+ #:search_note,
238
+ #:delete_note,
239
+ #:add_note,
240
+ #:get_note,
241
+ #++
@@ -12,7 +12,7 @@ module Memotoo
12
12
  # @connect=Memotoo::Connect.new("myusername","mypassword")
13
13
 
14
14
  # # retrieving search results
15
- # @response = @connect.searchContact("ka")
15
+ # @response = @connect.searchContact({:search=>"ka"})
16
16
 
17
17
  # # get a contact from id
18
18
  # @response = @connect.getContact(12345)
@@ -29,6 +29,16 @@ module Memotoo
29
29
  #++ @response.each {|contact|puts contact[:id]+"-"+contact[:firstname]+" "+contact[:lastname]}
30
30
 
31
31
 
32
+ # required: lastname
33
+ #
34
+ # optional: all other contact_details - see below
35
+ def addContact(details={})
36
+ if has_needed_fields(details, :lastname)
37
+ format_result(addApiCall({:contact => details}), :id)
38
+ end
39
+ end
40
+
41
+
32
42
  #[searchparameter:]
33
43
  # {:search=>"something", :limit_start=>0, :limit_nb=>100}
34
44
  #* required:
@@ -37,85 +47,48 @@ module Memotoo
37
47
  # limit_start
38
48
  # limit_nb
39
49
  #e.g. @connect.searchContact({:search=>"ka", :limit_nb=>50})
40
-
50
+ #
51
+ # returns nil or a hash of one contact or an array of contacts
52
+ #
41
53
  def searchContact(searchparameter={})
42
- check=has_fields(searchparameter, :search)
43
- if check[0]
44
- search = { :limit_start => '0',
45
- :limit_nb => '100'
46
- }.merge!(searchparameter)
47
- search_response = apicall(:searchContact, search)
48
- # returns an array of contacts from search result
49
- if search_response.nil? || search_response==""
50
- nil
51
- else
52
- search_response.to_hash.seek :search_contact_response, :return, :contact
53
- end
54
-
55
- else
56
- # returns false and a message
57
- go_home(check[1])
54
+ if has_needed_search_parameter(searchparameter)
55
+ format_result(searchApiCall(searchparameter), :return, :contact)
58
56
  end
59
57
  end
60
58
 
61
59
  # id = integer
62
60
  # e.g. @connect.getContact(12345)
61
+ #
62
+ # returns the contact or nil
63
+ #
63
64
  def getContact(id)
64
- contact = apicall(:getContact, { :id => id })
65
- # returns the contact
66
- contact.to_hash.seek :get_contact_response, :return, :contact
65
+ format_result(getApiCall(id), :return, :contact)
67
66
  end
68
67
 
69
-
70
68
  # get modified contacts since date
71
69
  # datetime = "2010-02-23 10:00:00" or just "2010-02-23"
72
70
  # e.g. @connect.getContactSync("2010-02-23 10:00:00")
73
71
  def getContactSync(datetime)
74
- date2time=Time.mktime(*ParseDate.parsedate(datetime))
75
- formated_date=date2time.strftime("%Y-%m-%d %H:%M:%S")
76
- #datetime=datetime.to_time.strftime("%Y-%m-%d %H:%M:%S")
77
- contacts = apicall(:getContactSync, { :date => formated_date })
78
- contacts.to_hash.seek :get_contact_sync_response, :return, :contact
79
- end
80
-
81
-
82
- # id = integer
83
- # e.g. @connect.deleteContact(12345)
84
- def deleteContact(id)
85
- contact = apicall(:deleteContact, { :id => id })
86
- # deletes the contact - returns true when contact is deleted
87
- contact.to_hash.seek :delete_contact_response, :ok
72
+ format_result(getSyncApiCall(datetime), :return, :contact)
88
73
  end
89
74
 
90
75
  # required: lastname and id
91
76
  #
92
77
  # optional: all other \contact_details - see contact fields at bottom
78
+ # return true if the changed happened
93
79
  def modifyContact(details={})
94
- check=has_fields(details, :lastname, :id)
95
- if check[0]
96
- contact = apicall(:modifyContact, { :contact => details })
97
- # return true if the changed happened
98
- contact.to_hash.seek :modify_contact_response, :ok
99
- else
100
- # returns false, if lastname and id is not given
101
- go_home(check[1])
80
+ if has_needed_fields(details, :lastname, :id)
81
+ format_result(modifyApiCall({:contact => details}), :ok)
102
82
  end
103
83
  end
104
84
 
105
- # required: lastname
106
- #
107
- # optional: all other contact_details
108
- def addContact(details={})
109
- check=has_fields(details, :lastname)
110
- if check[0]
111
- contact = apicall(:addContact, { :contact => details })
112
- # return the id from the new contact -> get it in my own db? maybe
113
- contact.to_hash.seek :add_contact_response, :id
114
- else
115
- # returns false, if lastname is not given
116
- go_home(check[1])
117
- end
118
- end
85
+ # id = integer
86
+ # e.g. @connect.deleteContact(12345)
87
+ # return true when contact is deleted
88
+ def deleteContact(id)
89
+ format_result(deleteApiCall(id), :ok)
90
+ end
91
+
119
92
 
120
93
  # ----------------------------------------
121
94
  #:section: contact_details
@@ -180,26 +153,6 @@ module Memotoo
180
153
  # :photo => '', // Photo encoded with Base64
181
154
  # ----------------------------------------
182
155
 
183
-
184
- private
185
-
186
- def go_home(message)
187
- puts "missing fields: " + message.to_s
188
- false
189
- end
190
-
191
- def has_fields(thehash, *args)
192
- valid=true
193
- retarr=[]
194
- args.each do |arg_item|
195
- unless thehash.has_key?(arg_item)
196
- valid = false
197
- retarr << arg_item
198
- end
199
- end
200
- [valid, retarr]
201
- end
202
-
203
156
 
204
157
  end # class
205
158