comufyrails 0.1.1 → 0.1.2b

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.
@@ -1,6 +1,6 @@
1
1
  require "em-synchrony"
2
2
  require "em-synchrony/em-http"
3
- require "comufyrails"
3
+ require 'comufyrails'
4
4
 
5
5
  # This module contains asynchronous methods for contacting the +comufy.url+ specified in +Config+.
6
6
  # It uses +em-synchrony+ and +EventMachine+ to achieve this, and therefore to be run asynchronously you
@@ -11,253 +11,255 @@ require "comufyrails"
11
11
  #
12
12
  # Requests for users and tags can return information and will yield to a block if provided, otherwise they will
13
13
  # also print to the log. This is often useful for debugging, but in practise you should provide these with a block.
14
- module Comufyrails::Connection
14
+ module Comufyrails
15
+ module Connection
15
16
 
16
- class IllegalKeyTypeError < StandardError; end
17
- class IllegalValueTypeError < StandardError; end
17
+ class IllegalKeyTypeError < StandardError; end
18
+ class IllegalValueTypeError < StandardError; end
18
19
 
19
- class << self
20
+ class << self
20
21
 
21
- # Shortened method name for storing a user, or users in your Application.
22
- # Please see +store_users+ for details.
23
- def store(uids, tags) self.store_user(uids, tags) end
22
+ # Shortened method name for storing a user, or users in your Application.
23
+ # Please see +store_users+ for details.
24
+ def store(uids, tags) self.store_user(uids, tags) end
24
25
 
25
- # This API call allows you to register a Facebook user of your application into Comufy’s social CRM.
26
- # If this user was already registered with Comufy, their information will be updated.
27
- #
28
- # * (String) +uid+ - The Facebook ID of the user you'll be adding.
29
- # * (Hash) +tags+ - The tags you'll setting for this user.
30
- # * (String) +tag_name+ - Must correspond to one of the tag names of the application.
31
- # * (String) +value+ - Must be the correct value type for that tag.
32
- #
33
- # = Example
34
- #
35
- # Comufyrails::Connection.store_user USER_FACEBOOK_ID, { dob: '1978-10-01 19:50:48' }
36
- def store_user(uids, tags)
37
- uids = [uids] unless uids.is_a? Array
38
- tags = [tags] unless tags.is_a? Array
39
- self.store_users(uids, tags)
40
- end
26
+ # This API call allows you to register a Facebook user of your application into Comufy’s social CRM.
27
+ # If this user was already registered with Comufy, their information will be updated.
28
+ #
29
+ # * (String) +uid+ - The Facebook ID of the user you'll be adding.
30
+ # * (Hash) +tags+ - The tags you'll setting for this user.
31
+ # * (String) +tag_name+ - Must correspond to one of the tag names of the application.
32
+ # * (String) +value+ - Must be the correct value type for that tag.
33
+ #
34
+ # = Example
35
+ #
36
+ # Comufyrails::Connection.store_user USER_FACEBOOK_ID, { dob: '1978-10-01 19:50:48' }
37
+ def store_user(uids, tags)
38
+ uids = [uids] unless uids.is_a? Array
39
+ tags = [tags] unless tags.is_a? Array
40
+ self.store_users(uids, tags)
41
+ end
41
42
 
42
- # This API call allows you to register multiple Facebook users of your application into Comufy’s social CRM.
43
- # If these users were already registered into Comufy, their information will be updated.
44
- #
45
- # Please note that you can provide a single String or Integer for uids and one +tag+ if you wish.
46
- #
47
- # * (Array) +uids+ - A list of (String/Integer) user ids you wish to add/update.
48
- # * (Array) +tags+ - A list of hashes for each of the users.
49
- # * (Hash) +tag+
50
- # * (String) +tag_name+ - Must correspond to one of the tag names of the application.
51
- # * (String) +value+ - Must be the correct value type for that tag.
52
- #
53
- # = Example
54
- #
55
- # Comufyrails::Connection.store_users(
56
- # [ USER_ID, USER_ID_2 ],
57
- # [ { 'dob' => '1978-10-01 19:50:48' }, { 'dob' => '1978-10-01 19:50:48'}]
58
- # )
59
- def store_users(uids, tags)
60
- raise ArgumentError, "uids must be an Array." unless uids.is_a? Array
61
- raise ArgumentError, "tags must be an Array." unless tags.is_a? Array
43
+ # This API call allows you to register multiple Facebook users of your application into Comufy’s social CRM.
44
+ # If these users were already registered into Comufy, their information will be updated.
45
+ #
46
+ # Please note that you can provide a single String or Integer for uids and one +tag+ if you wish.
47
+ #
48
+ # * (Array) +uids+ - A list of (String/Integer) user ids you wish to add/update.
49
+ # * (Array) +tags+ - A list of hashes for each of the users.
50
+ # * (Hash) +tag+
51
+ # * (String) +tag_name+ - Must correspond to one of the tag names of the application.
52
+ # * (String) +value+ - Must be the correct value type for that tag.
53
+ #
54
+ # = Example
55
+ #
56
+ # Comufyrails::Connection.store_users(
57
+ # [ USER_ID, USER_ID_2 ],
58
+ # [ { 'dob' => '1978-10-01 19:50:48' }, { 'dob' => '1978-10-01 19:50:48'}]
59
+ # )
60
+ def store_users(uids, tags)
61
+ raise ArgumentError, "uids must be an Array." unless uids.is_a? Array
62
+ raise ArgumentError, "tags must be an Array." unless tags.is_a? Array
62
63
 
63
- # Ensure the tags are valid
64
- tags.each(&:symbolize_keys!)
65
- zipped = uids.zip(tags)
64
+ # Ensure the tags are valid
65
+ tags.each(&:symbolize_keys!)
66
+ zipped = uids.zip(tags)
66
67
 
67
- data = {
68
- cd: '88',
69
- token: Comufyrails.config.access_token,
70
- applicationName: Comufyrails.config.app_name,
71
- accounts: zipped.map { |uid, tagged | Hash[:account, { fbId: uid.to_s }, :tags, tagged] }
72
- }
73
- EM.synchrony do
74
- http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
75
- :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
76
- if http.response_header.status == 200
77
- message = JSON.parse(http.response)
78
- case message["cd"]
79
- when 388 then
80
- p "388 - Success! - data = #{data} - message = #{message}."
81
- when 475 then
82
- p "475 - Invalid parameter provided. - data = #{data} - message = #{message}."
83
- when 617 then
84
- p "617 - Some of the tags passed are not registered. - data = #{data} - message = #{message}."
85
- when 632 then
86
- p "632 - _ERROR_FACEBOOK_PAGE_NOT_FOUND - data = #{data} - message = #{message}."
87
- else
88
- p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
68
+ data = {
69
+ cd: '88',
70
+ token: Comufyrails.config.access_token,
71
+ applicationName: Comufyrails.config.app_name,
72
+ accounts: zipped.map { |uid, tagged | Hash[:account, { fbId: uid.to_s }, :tags, tagged] }
73
+ }
74
+ EM.synchrony do
75
+ http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
76
+ :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
77
+ if http.response_header.status == 200
78
+ message = JSON.parse(http.response)
79
+ case message["cd"]
80
+ when 388 then
81
+ p "388 - Success! - data = #{data} - message = #{message}."
82
+ when 475 then
83
+ p "475 - Invalid parameter provided. - data = #{data} - message = #{message}."
84
+ when 617 then
85
+ p "617 - Some of the tags passed are not registered. - data = #{data} - message = #{message}."
86
+ when 632 then
87
+ p "632 - _ERROR_FACEBOOK_PAGE_NOT_FOUND - data = #{data} - message = #{message}."
88
+ else
89
+ p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
90
+ end
91
+ else
92
+ p "Server responded with #{http.response_header}."
89
93
  end
90
- else
91
- p "Server responded with #{http.response_header}."
92
94
  end
93
95
  end
94
- end
95
96
 
96
- # Shorthand method for sending messages to the selected uids. See +send_facebook_message+ for more information.
97
- def message(desc, content, uids, opts = {}) self.send_facebook_message(desc, content, uids, opts) end
97
+ # Shorthand method for sending messages to the selected uids. See +send_facebook_message+ for more information.
98
+ def message(desc, content, uids, opts = {}) self.send_facebook_message(desc, content, uids, opts) end
98
99
 
99
- # Sends a message with the description and content to the facebook id or id's specified, allowing multiple
100
- # options to be set concerning the privacy, and content of the message.
101
- #
102
- # * (String) +description+ - Description of the message. Useful to aggregate data in the Comufy dashboard.
103
- # * (String) +content+ - The text message content.
104
- # * (Array) +uids+ - The Facebook IDs of the users to send the message to.
105
- # * (Hash) +opts+ - Optional settings you can pass.
106
- # * (Integer) +delivery_time+ - The scheduled time of delivery defaults to now. (Unix millisecond timestamps)
107
- # * (Boolean) +shorten_urls+ - UNTRACKED if false, otherwise defaults to Comufy TRACKED
108
- # * (String) +filter+ - filtering condition in CFL.
109
- # * (Hash) +message_options+ - options to set for the message especially.
110
- # * (String) +name+ - facebook message name.
111
- # * (String) +link+ - Facebook message link.
112
- # * (String) +caption+ - facebook message caption.
113
- # * (String) +description+ - description of the message.
114
- # * (String) +picture+ - URL of the image that should appear on the image section of the message.
115
- # * (Boolean) +privacy+ - whether the message should be sent private or not.
116
- #
117
- # = Example
118
- # Comufyrails::Connection.send_facebook_message(
119
- # DESCRIPTION, CONTENT_GOES_HERE, UIDS,
120
- # message_options: {
121
- # private: true, link: 'www.example.com', name: 'test', description: 'description'
122
- # }
123
- # )
124
- def send_facebook_message(description, content, uids, opts = {})
125
- raise ArgumentError, "Description must be a String." unless description.is_a? String
126
- raise ArgumentError, "Content must be a String." unless content.is_a? String
127
- raise ArgumentError, "Uids must be an Array." unless uids.is_a? Array
128
- raise ArgumentError, "Opts must be a Hash if you include it." unless opts.is_a? Hash
100
+ # Sends a message with the description and content to the facebook id or id's specified, allowing multiple
101
+ # options to be set concerning the privacy, and content of the message.
102
+ #
103
+ # * (String) +description+ - Description of the message. Useful to aggregate data in the Comufy dashboard.
104
+ # * (String) +content+ - The text message content.
105
+ # * (Array) +uids+ - The Facebook IDs of the users to send the message to.
106
+ # * (Hash) +opts+ - Optional settings you can pass.
107
+ # * (Integer) +delivery_time+ - The scheduled time of delivery defaults to now. (Unix millisecond timestamps)
108
+ # * (Boolean) +shorten_urls+ - UNTRACKED if false, otherwise defaults to Comufy TRACKED
109
+ # * (String) +filter+ - filtering condition in CFL.
110
+ # * (Hash) +message_options+ - options to set for the message especially.
111
+ # * (String) +name+ - facebook message name.
112
+ # * (String) +link+ - Facebook message link.
113
+ # * (String) +caption+ - facebook message caption.
114
+ # * (String) +description+ - description of the message.
115
+ # * (String) +picture+ - URL of the image that should appear on the image section of the message.
116
+ # * (Boolean) +privacy+ - whether the message should be sent private or not.
117
+ #
118
+ # = Example
119
+ # Comufyrails::Connection.send_facebook_message(
120
+ # DESCRIPTION, CONTENT_GOES_HERE, UIDS,
121
+ # message_options: {
122
+ # private: true, link: 'www.example.com', name: 'test', description: 'description'
123
+ # }
124
+ # )
125
+ def send_facebook_message(description, content, uids, opts = {})
126
+ raise ArgumentError, "Description must be a String." unless description.is_a? String
127
+ raise ArgumentError, "Content must be a String." unless content.is_a? String
128
+ raise ArgumentError, "Uids must be an Array." unless uids.is_a? Array
129
+ raise ArgumentError, "Opts must be a Hash if you include it." unless opts.is_a? Hash
129
130
 
130
- opts.symbolize_keys!
131
+ opts.symbolize_keys!
131
132
 
132
- facebook_ids = "FACEBOOK.ID=\"#{uids.join('\" OR FACEBOOK.ID=\"')}\""
133
- filter = opts[:filter] || ""
134
- delivery_time = opts[:delivery_time]
135
- shorten_urls = opts.has_key?(:shorten_urls) ? opts[:shorten_urls] : true
136
- options = opts[:message_options]
133
+ facebook_ids = "FACEBOOK.ID=\"#{uids.join('\" OR FACEBOOK.ID=\"')}\""
134
+ filter = opts[:filter] || ""
135
+ delivery_time = opts[:delivery_time]
136
+ shorten_urls = opts.has_key?(:shorten_urls) ? opts[:shorten_urls] : true
137
+ options = opts[:message_options]
137
138
 
138
- data = {
139
- cd: 83,
140
- token: Comufyrails.config.access_token,
141
- applicationName: Comufyrails.config.app_name,
142
- description: description,
143
- content: content,
144
- filter: "#{facebook_ids} #{filter}"
145
- }
146
- data[:deliveryTime] = delivery_time if delivery_time
147
- data[:trackingMode] = "UNTRACKED" unless shorten_urls
148
- data[:facebookTargetingMode] = "NOTIFICATION"
139
+ data = {
140
+ cd: 83,
141
+ token: Comufyrails.config.access_token,
142
+ applicationName: Comufyrails.config.app_name,
143
+ description: description,
144
+ content: content,
145
+ filter: "#{facebook_ids} #{filter}"
146
+ }
147
+ data[:deliveryTime] = delivery_time if delivery_time
148
+ data[:trackingMode] = "UNTRACKED" unless shorten_urls
149
+ data[:facebookTargetingMode] = "NOTIFICATION"
149
150
 
150
- if options
151
- data[:fbMessagePrivacyMode] = options[:private] ? "PRIVATE" : "PUBLIC" if options.has_key?(:private)
152
- data[:fbMessageCaption] = options[:caption] if options.has_key?(:caption)
153
- data[:fbMessageLink] = options[:link] if options.has_key?(:link)
154
- data[:fbMessageName] = options[:name] if options.has_key?(:name)
155
- data[:fbMessageDescription] = options[:description] if options.has_key?(:description)
156
- data[:fbMessagePictureUrl] = options[:picture] if options.has_key?(:picture)
157
- end
158
-
159
- EM.synchrony do
160
- http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
161
- :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
162
- if http.response_header.status == 200
163
- message = JSON.parse(http.response)
164
- case message["cd"]
165
- when 383 then
166
- p "383 - Success! - data = #{data} - message = #{message}."
167
- when 416 then
168
- p "416 - _ERROR_MSG_SEND_FAILED - data = #{data} - message = #{message}."
169
- when 475 then
170
- p "475 - Invalid parameters provided - data = #{data} - message = #{message}."
171
- when 551 then
172
- p "551 _ERROR_TAG_VALUE_NOT_FOUND - data = #{data} - message = #{message}."
173
- when 603 then
174
- p "603 - _ERROR_DOMAIN_APPLICATION_NAME_NOT_FOUND - data = #{data} - message = #{message}."
175
- when 607 then
176
- p "607 - _ERROR_UNAUTHORISED_ACTION - data = #{data} - message = #{message}."
177
- when 617 then
178
- p "617 - _ERROR_DOMAIN_APPLICATION_TAG_NOT_FOUND - data = #{data} - message = #{message}."
179
- when 648 then
180
- p "648 - _ERROR_FACEBOOK_APPLICATION_USER_NOT_FOUND - data = #{data} - message = #{message}."
181
- when 673 then
182
- p "673 - Invalid time exception - data = #{data} - message = #{message}."
183
- when 679 then
184
- p "679 - _ERROR_MALFORMED_TARGETING_EXPRESSION - data = #{data} - message = #{message}."
185
- else
186
- p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
187
- end
188
- else
189
- p "Server responded with #{http.response_header}."
151
+ if options
152
+ data[:fbMessagePrivacyMode] = options[:private] ? "PRIVATE" : "PUBLIC" if options.has_key?(:private)
153
+ data[:fbMessageCaption] = options[:caption] if options.has_key?(:caption)
154
+ data[:fbMessageLink] = options[:link] if options.has_key?(:link)
155
+ data[:fbMessageName] = options[:name] if options.has_key?(:name)
156
+ data[:fbMessageDescription] = options[:description] if options.has_key?(:description)
157
+ data[:fbMessagePictureUrl] = options[:picture] if options.has_key?(:picture)
190
158
  end
191
- end
192
- end
193
159
 
194
- # Provides a list of all tags for this application. If you provide a block it will yield the response,
195
- # otherwise it will be sent the log.
196
- def tags
197
- data = {
198
- cd: 101,
199
- token: Comufyrails.config.access_token,
200
- applicationName: Comufyrails.config.app_name
201
- }
202
-
203
- EM.synchrony do
204
- http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
205
- :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
206
- if http.response_header.status == 200
207
- message = JSON.parse(http.response)
208
- if block_given?
209
- yield message
210
- else
160
+ EM.synchrony do
161
+ http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
162
+ :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
163
+ if http.response_header.status == 200
164
+ message = JSON.parse(http.response)
211
165
  case message["cd"]
212
- when 219 then
213
- p "219 - Success! - data = #{data} - message = #{message}."
166
+ when 383 then
167
+ p "383 - Success! - data = #{data} - message = #{message}."
168
+ when 416 then
169
+ p "416 - _ERROR_MSG_SEND_FAILED - data = #{data} - message = #{message}."
170
+ when 475 then
171
+ p "475 - Invalid parameters provided - data = #{data} - message = #{message}."
172
+ when 551 then
173
+ p "551 _ERROR_TAG_VALUE_NOT_FOUND - data = #{data} - message = #{message}."
174
+ when 603 then
175
+ p "603 - _ERROR_DOMAIN_APPLICATION_NAME_NOT_FOUND - data = #{data} - message = #{message}."
176
+ when 607 then
177
+ p "607 - _ERROR_UNAUTHORISED_ACTION - data = #{data} - message = #{message}."
178
+ when 617 then
179
+ p "617 - _ERROR_DOMAIN_APPLICATION_TAG_NOT_FOUND - data = #{data} - message = #{message}."
180
+ when 648 then
181
+ p "648 - _ERROR_FACEBOOK_APPLICATION_USER_NOT_FOUND - data = #{data} - message = #{message}."
182
+ when 673 then
183
+ p "673 - Invalid time exception - data = #{data} - message = #{message}."
184
+ when 679 then
185
+ p "679 - _ERROR_MALFORMED_TARGETING_EXPRESSION - data = #{data} - message = #{message}."
214
186
  else
215
187
  p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
216
188
  end
189
+ else
190
+ p "Server responded with #{http.response_header}."
217
191
  end
218
- else
219
- p "Server responded with #{http.response_header}."
220
192
  end
221
193
  end
222
- end
223
194
 
224
- # Lists all current users data, with any additional filters you want.
225
- # If you provide a block it will yield the response, otherwise it will be sent the log.
226
- # TODO: Replace USER.USER_STATE with something we know will get all users.
227
- def users filter = ""
228
- filter = 'USER.USER_STATE="Unknown"' if filter.empty?
229
- data = {
230
- cd: 82,
231
- token: Comufyrails.config.access_token,
232
- applicationName: Comufyrails.config.app_name,
233
- since: 1314835200000,
234
- fetchMode: "ALL",
235
- filter: filter
236
- }
195
+ # Provides a list of all tags for this application. If you provide a block it will yield the response,
196
+ # otherwise it will be sent the log.
197
+ def tags
198
+ data = {
199
+ cd: 101,
200
+ token: Comufyrails.config.access_token,
201
+ applicationName: Comufyrails.config.app_name
202
+ }
237
203
 
238
- EM.synchrony do
239
- http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
240
- :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
241
- if http.response_header.status == 200
242
- message = JSON.parse(http.response)
243
- if block_given?
244
- yield message
204
+ EM.synchrony do
205
+ http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
206
+ :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
207
+ if http.response_header.status == 200
208
+ message = JSON.parse(http.response)
209
+ if block_given?
210
+ yield message
211
+ else
212
+ case message["cd"]
213
+ when 219 then
214
+ p "219 - Success! - data = #{data} - message = #{message}."
215
+ else
216
+ p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
217
+ end
218
+ end
245
219
  else
246
- case message["cd"]
247
- when 382 then
248
- p "382 - Success! - data = #{data} - message = #{message}."
249
- when 692 then
250
- p "692 - Invalid filter/filter not found - data = #{data} - message = #{message}."
251
- else
252
- p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
220
+ p "Server responded with #{http.response_header}."
221
+ end
222
+ end
223
+ end
224
+
225
+ # Lists all current users data, with any additional filters you want.
226
+ # If you provide a block it will yield the response, otherwise it will be sent the log.
227
+ # TODO: Replace USER.USER_STATE with something we know will get all users.
228
+ def users filter = ""
229
+ filter = 'USER.USER_STATE="Unknown"' if filter.empty?
230
+ data = {
231
+ cd: 82,
232
+ token: Comufyrails.config.access_token,
233
+ applicationName: Comufyrails.config.app_name,
234
+ since: 1314835200000,
235
+ fetchMode: "ALL",
236
+ filter: filter
237
+ }
238
+
239
+ EM.synchrony do
240
+ http = EventMachine::HttpRequest.new(Comufyrails.config.url).post(
241
+ :body => { request: data.to_json }, :initheader => { 'Content-Type' => 'application/json' })
242
+ if http.response_header.status == 200
243
+ message = JSON.parse(http.response)
244
+ if block_given?
245
+ yield message
246
+ else
247
+ case message["cd"]
248
+ when 382 then
249
+ p "382 - Success! - data = #{data} - message = #{message}."
250
+ when 692 then
251
+ p "692 - Invalid filter/filter not found - data = #{data} - message = #{message}."
252
+ else
253
+ p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
254
+ end
253
255
  end
256
+ else
257
+ p "Server responded with #{http.response_header}."
254
258
  end
255
- else
256
- p "Server responded with #{http.response_header}."
257
259
  end
258
260
  end
259
- end
260
261
 
262
+ end
261
263
  end
262
264
 
263
265
  end
@@ -1,4 +1,4 @@
1
1
  module Comufyrails
2
2
  # Current version of this gem.
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2b"
4
4
  end
data/lib/comufyrails.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'rails'
2
2
 
3
3
  require "comufyrails/core_ext"
4
- require "comufyrails/connection"
4
+ require "comufyrails/version"
5
5
  require "comufyrails/constants"
6
+ require "comufyrails/connection"
6
7
  require 'comufyrails/railtie' if defined?(Rails)
7
- require "comufyrails/version"
8
8
 
9
9
  module Comufyrails
10
10
 
@@ -17,11 +17,11 @@ namespace :comufy do
17
17
  Please check config.comufy_rails.app_name in your environment initializer or the environment variable
18
18
  COMUFY_APP_NAME are valid strings.
19
19
  "
20
- elsif Comufyrails.config.base_api_url.blank?
20
+ elsif Comufyrails.config.url.blank?
21
21
  p "
22
22
  Cannot find the base api url, is it currently set to nil or an empty string?\n
23
- Please check config.comufy_rails.base_api_url in your environment initializer or the environment variable
24
- COMUFY_BASE_API_URL are valid strings.
23
+ Please check config.comufy_rails.url in your environment initializer or the environment variable
24
+ COMUFY_URL are valid strings.
25
25
  "
26
26
  elsif Comufyrails.config.access_token.blank?
27
27
  p "
@@ -42,7 +42,12 @@ namespace :comufy do
42
42
  type: args.type.to_sym
43
43
  }]
44
44
  }
45
- response = call_api(Comufyrails.config.url, data)
45
+
46
+ uri = URI.parse(Comufyrails.config.url)
47
+ http = Net::HTTP.new(uri.host, uri.port)
48
+ request = Net::HTTP::Post.new(uri.path, initheader = { 'Content-Type' => 'application/json' })
49
+ request.set_form_data({ request: data.to_json })
50
+ response = http.request(request)
46
51
 
47
52
  if response.message == 'OK'
48
53
  message = JSON.parse(response.read_body)
@@ -76,11 +81,11 @@ namespace :comufy do
76
81
  Please check config.comufy_rails.app_name in your environment initializer or the environment variable
77
82
  COMUFY_APP_NAME are valid strings.
78
83
  "
79
- elsif Comufyrails.config.base_api_url.blank?
84
+ elsif Comufyrails.config.url.blank?
80
85
  p "
81
86
  Cannot find the base api url, is it currently set to nil or an empty string?\n
82
- Please check config.comufy_rails.base_api_url in your environment initializer or the environment variable
83
- COMUFY_BASE_API_URL are valid strings.
87
+ Please check config.comufy_rails.url in your environment initializer or the environment variable
88
+ COMUFY_URL are valid strings.
84
89
  "
85
90
  elsif Comufyrails.config.access_token.blank?
86
91
  p "
@@ -95,7 +100,12 @@ namespace :comufy do
95
100
  token: Comufyrails.config.access_token,
96
101
  tag: args.name
97
102
  }
98
- response = call_api(Comufyrails.config.url, data)
103
+
104
+ uri = URI.parse(Comufyrails.config.url)
105
+ http = Net::HTTP.new(uri.host, uri.port)
106
+ request = Net::HTTP::Post.new(uri.path, initheader = { 'Content-Type' => 'application/json' })
107
+ request.set_form_data({ request: data.to_json })
108
+ response = http.request(request)
99
109
 
100
110
  if response.message == 'OK'
101
111
  message = JSON.parse(response.read_body)
@@ -113,19 +123,10 @@ namespace :comufy do
113
123
  else
114
124
  p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
115
125
  end
126
+ else
127
+ p "Authentication failed when sending #{data}. Please get in touch with Comufy if you cannot resolve this."
116
128
  end
117
129
  end
118
130
  end
119
131
 
120
- private
121
-
122
- # posts the form to the given url as json and blocks till a response is given.
123
- def call_api(url, data)
124
- uri = URI.parse(url)
125
- http = Net::HTTP.new(uri.host, uri.port)
126
- request = Net::HTTP::Post.new(uri.path, initheader = { 'Content-Type' => 'application/json' })
127
- request.set_form_data({ request: data.to_json })
128
- http.request(request)
129
- end
130
-
131
132
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comufyrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2b
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - plcstevens
@@ -127,13 +127,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
- - - ! '>='
130
+ - - ! '>'
131
131
  - !ruby/object:Gem::Version
132
- version: '0'
132
+ version: 1.3.1
133
133
  requirements: []
134
134
  rubyforge_project:
135
135
  rubygems_version: 1.8.24
136
136
  signing_key:
137
137
  specification_version: 3
138
- summary: comufyrails-0.1.1
138
+ summary: comufyrails-0.1.2b
139
139
  test_files: []