comufyrails 0.1.3 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -3
- data/lib/comufyrails/connection.rb +15 -1
- data/lib/comufyrails/version.rb +1 -1
- data/lib/tasks/comufyrails.rake +78 -30
- metadata +2 -2
data/README.md
CHANGED
@@ -41,12 +41,24 @@ can get these values by using this heroku command below and looking for all valu
|
|
41
41
|
|
42
42
|
heroku config
|
43
43
|
|
44
|
+
### Application Name
|
45
|
+
|
46
|
+
If you do not already have a Comufy application setup you need to before you can start to use this gem.
|
47
|
+
|
48
|
+
First you should register your Facebook application and get the Facebook ID and Facebook
|
49
|
+
secret of the application. You will use these in the rake method below to register the application with Comufy.
|
50
|
+
On success of this you can write the name of your application in the manners shown further below.
|
51
|
+
|
52
|
+
```bash
|
53
|
+
rake comufy:app["MY_APPLICATION_NAME","APP_ID","APP_SECRET","Description of my application"]
|
54
|
+
```
|
55
|
+
|
44
56
|
You can set the values in your config/environments/*.rb in the same manner you set rails-specific values.
|
45
57
|
|
46
58
|
```ruby
|
47
59
|
config.comufy_rails.app_name = 'YOUR_APPLICATION_NAME'
|
48
60
|
config.comufy_rails.access_token = 'YOUR_ACCESS_TOKEN'
|
49
|
-
config.comufy_rails.url
|
61
|
+
config.comufy_rails.url = 'COMUFY'
|
50
62
|
```
|
51
63
|
|
52
64
|
Alternatively you can set these in your environment/path.
|
@@ -54,7 +66,7 @@ Alternatively you can set these in your environment/path.
|
|
54
66
|
```
|
55
67
|
COMUFY_APP_NAME - Application name on Comufy, defaults to your Ruby on Rails application name.
|
56
68
|
COMUFY_TOKEN - Token given to you by our Comufy Heroku service or from Comufy directly.
|
57
|
-
COMUFY_URL
|
69
|
+
COMUFY_URL - Full HTTP address to connect to, defaults to our service.
|
58
70
|
```
|
59
71
|
|
60
72
|
## Usage
|
@@ -101,7 +113,7 @@ There are also a number of methods that are added to your rake environment, for
|
|
101
113
|
the ability to add/remove tags for users of your applications.
|
102
114
|
|
103
115
|
```bash
|
104
|
-
$ bundle exec rake comufy:tag["DOB",
|
116
|
+
$ bundle exec rake comufy:tag["DOB","DATE"]
|
105
117
|
```
|
106
118
|
|
107
119
|
This will run a blocking call to register this tag with your application, informing you if it was successful or not.
|
@@ -222,6 +222,16 @@ module Comufyrails
|
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
+
def user(facebook_id)
|
226
|
+
filter = "FACEBOOK.ID=\"#{facebook_id}\""
|
227
|
+
self.users(filter) do |users, total, to, from|
|
228
|
+
user = users.first
|
229
|
+
account = user.delete("account")
|
230
|
+
tags = user.delete("tagValues")
|
231
|
+
yield account, tags, [users, total, to, from]
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
225
235
|
# Lists all current users data, with any additional filters you want.
|
226
236
|
# If you provide a block it will yield the response, otherwise it will be sent the log.
|
227
237
|
# TODO: Replace USER.USER_STATE with something we know will get all users.
|
@@ -242,7 +252,11 @@ module Comufyrails
|
|
242
252
|
if http.response_header.status == 200
|
243
253
|
message = JSON.parse(http.response)
|
244
254
|
if block_given?
|
245
|
-
|
255
|
+
total = message["timeBlocks"][0]["total"]
|
256
|
+
users = message["timeBlocks"][0]["data"]
|
257
|
+
to = message["timeBlocks"][0]["to"]
|
258
|
+
from = message["timeBlocks"][0]["from"]
|
259
|
+
yield users, total, to, from
|
246
260
|
else
|
247
261
|
case message["cd"]
|
248
262
|
when 382 then
|
data/lib/comufyrails/version.rb
CHANGED
data/lib/tasks/comufyrails.rake
CHANGED
@@ -5,34 +5,30 @@ require 'uri'
|
|
5
5
|
|
6
6
|
namespace :comufy do
|
7
7
|
|
8
|
-
desc "Register a tag with your application.
|
9
|
-
#{Comufyrails::LEGAL_TYPES.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')},
|
10
|
-
if empty it defaults to STRING."
|
8
|
+
desc "Register a tag with your application."
|
11
9
|
task :tag , [:name, :type] => :environment do |t, args|
|
12
10
|
raise ArgumentError, "Must specify a name for the tag." unless args.name
|
13
11
|
args.with_defaults(type: 'STRING')
|
14
12
|
|
15
13
|
if Comufyrails.config.app_name.blank?
|
16
14
|
p "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
Cannot find the application name, is it currently set to nil or an empty string? Please check
|
16
|
+
config.comufy_rails.app_name in your environment initializer or the environment variable
|
17
|
+
COMUFY_APP_NAME are valid strings. And remember you need to register your application with Comufy first with
|
18
|
+
the comufy:app rake command."
|
21
19
|
elsif Comufyrails.config.url.blank?
|
22
20
|
p "
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"
|
21
|
+
Cannot find the base api url, is it currently set to nil or an empty string?\n
|
22
|
+
Please check config.comufy_rails.url in your environment initializer or the environment variable
|
23
|
+
COMUFY_URL are valid strings."
|
27
24
|
elsif Comufyrails.config.access_token.blank?
|
28
25
|
p "
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"
|
26
|
+
Cannot find the access token, is it currently set to nil or an empty string?\n
|
27
|
+
Please check config.comufy_rails.access_token in your environment initializer or the environment variable
|
28
|
+
COMUFY_TOKEN are valid strings."
|
33
29
|
elsif not Comufyrails::LEGAL_TYPES.include?(args.type)
|
34
|
-
p "
|
35
|
-
|
30
|
+
p "
|
31
|
+
The type must be #{Comufyrails::LEGAL_TYPES.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ')}"
|
36
32
|
else
|
37
33
|
data = {
|
38
34
|
cd: 86,
|
@@ -78,23 +74,21 @@ namespace :comufy do
|
|
78
74
|
raise ArgumentError, "Must specify a name for the tag." unless args.name
|
79
75
|
|
80
76
|
if Comufyrails.config.app_name.blank?
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
puts "
|
78
|
+
Cannot find the application name, is it currently set to nil or an empty string? Please check
|
79
|
+
config.comufy_rails.app_name in your environment initializer or the environment variable
|
80
|
+
COMUFY_APP_NAME are valid strings. And remember you need to register your application with Comufy first with
|
81
|
+
the comufy:app rake command."
|
86
82
|
elsif Comufyrails.config.url.blank?
|
87
83
|
p "
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
"
|
84
|
+
Cannot find the base api url, is it currently set to nil or an empty string?
|
85
|
+
Please check config.comufy_rails.url in your environment initializer or the environment variable
|
86
|
+
COMUFY_URL are valid strings."
|
92
87
|
elsif Comufyrails.config.access_token.blank?
|
93
88
|
p "
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
"
|
89
|
+
Cannot find the access token, is it currently set to nil or an empty string?
|
90
|
+
Please check config.comufy_rails.access_token in your environment initializer or the environment variable
|
91
|
+
COMUFY_TOKEN are valid strings."
|
98
92
|
else
|
99
93
|
data = {
|
100
94
|
cd: 85,
|
@@ -132,4 +126,58 @@ namespace :comufy do
|
|
132
126
|
end
|
133
127
|
end
|
134
128
|
|
129
|
+
desc "Register an application with Comufy"
|
130
|
+
task :app , [:name, :id, :secret, :description] => :environment do |t, args|
|
131
|
+
raise ArgumentError, "Must specify a name for the application." unless args.name
|
132
|
+
raise ArgumentError, "Must specify a facebook application id for the application." unless args.id
|
133
|
+
raise ArgumentError, "Must specify a facebook secret for the application." unless args.secret
|
134
|
+
raise ArgumentError, "Must specify a description for the application." unless args.description
|
135
|
+
|
136
|
+
if Comufyrails.config.url.blank?
|
137
|
+
p "
|
138
|
+
Cannot find the base api url, is it currently set to nil or an empty string?\n
|
139
|
+
Please check config.comufy_rails.url in your environment initializer or the environment variable
|
140
|
+
COMUFY_URL are valid strings."
|
141
|
+
elsif Comufyrails.config.access_token.blank?
|
142
|
+
p "
|
143
|
+
Cannot find the access token, is it currently set to nil or an empty string?\n
|
144
|
+
Please check config.comufy_rails.access_token in your environment initializer or the environment variable
|
145
|
+
COMUFY_TOKEN are valid strings."
|
146
|
+
else
|
147
|
+
data = {
|
148
|
+
cd: 106,
|
149
|
+
token: Comufyrails.config.access_token,
|
150
|
+
name: args.name,
|
151
|
+
description: args.description,
|
152
|
+
applicationId: args.id,
|
153
|
+
applicationSecret: args.secret
|
154
|
+
}
|
155
|
+
|
156
|
+
uri = URI.parse(Comufyrails.config.url)
|
157
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
158
|
+
http.use_ssl = true
|
159
|
+
request = Net::HTTP::Post.new(uri.path, initheader = { 'Content-Type' => 'application/json' })
|
160
|
+
request.set_form_data({ request: data.to_json })
|
161
|
+
response = http.request(request)
|
162
|
+
|
163
|
+
if response.message == 'OK'
|
164
|
+
message = JSON.parse(response.read_body)
|
165
|
+
case message['cd']
|
166
|
+
when 205 then
|
167
|
+
p "205 - Success! - data = #{data} - message = #{message}."
|
168
|
+
when 602 then
|
169
|
+
p "602 - _ERROR_DOMAIN_APPLICATION_NAME_ALREADY_REGISTERED - data = #{data} - message = #{message}."
|
170
|
+
when 619 then
|
171
|
+
p "619 - _ERROR_DOMAIN_APPLICATION_ALREADY_REGISTERED_UNDER_DIFFERENT_NAME - data = #{data} - message = #{message}."
|
172
|
+
when 645 then
|
173
|
+
p "645 - _ERROR_FACEBOOK_AUTHORISATION_FAILURE - data = #{data} - message = #{message}."
|
174
|
+
else
|
175
|
+
p "UNKNOWN RESPONSE - data = #{data} - message = #{message}."
|
176
|
+
end
|
177
|
+
else
|
178
|
+
p "Authentication failed when sending #{data}. Please get in touch with Comufy if you cannot resolve this."
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
135
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comufyrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -135,5 +135,5 @@ rubyforge_project:
|
|
135
135
|
rubygems_version: 1.8.24
|
136
136
|
signing_key:
|
137
137
|
specification_version: 3
|
138
|
-
summary: comufyrails-0.1.
|
138
|
+
summary: comufyrails-0.1.6
|
139
139
|
test_files: []
|