invity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/invity.gemspec +24 -0
- data/lib/.DS_Store +0 -0
- data/lib/invity.rb +9 -0
- data/lib/invity/facebook.rb +51 -0
- data/lib/invity/message.rb +78 -0
- data/lib/invity/version.rb +3 -0
- data/spec/.DS_Store +0 -0
- data/spec/spec_helper.rb +1 -0
- metadata +111 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
Invity
|
2
|
+
---
|
3
|
+
#### Send messages to Facebook Inbox with your rails app.
|
4
|
+
|
5
|
+
[-- demo --](invity.herokuapp.com)
|
6
|
+
|
7
|
+
Installation
|
8
|
+
---
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'invity'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install invity
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Requirements:
|
24
|
+
1. xmpp_login ( facebook permissions )
|
25
|
+
2. ENV['FACEBOOK\_APP\_ID']
|
26
|
+
3. ENV['FACEBOOK\_APP\_SECRET']
|
27
|
+
|
28
|
+
### eg:
|
29
|
+
using [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook)
|
30
|
+
|
31
|
+
In `config/initializer/omniauth.rb`
|
32
|
+
|
33
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
34
|
+
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: "email, xmpp_login"
|
35
|
+
end
|
36
|
+
|
37
|
+
Controller
|
38
|
+
---
|
39
|
+
|
40
|
+
@invitation = Invity::Facebook::API.new( access_token )
|
41
|
+
|
42
|
+
@friends = @invitation.friends
|
43
|
+
or
|
44
|
+
@friends = @invitation.friends_with_pics
|
45
|
+
or
|
46
|
+
@friends = @invitation.friend_ids
|
47
|
+
|
48
|
+
Send Message
|
49
|
+
---
|
50
|
+
- access_token == facebook access\_token from [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook)
|
51
|
+
- sender == user uid from [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook)
|
52
|
+
- recievers == Array of friends ids
|
53
|
+
- invitation == should be string
|
54
|
+
- body == should be string eg: `"#{Time.now}"`
|
55
|
+
|
56
|
+
|
57
|
+
---
|
58
|
+
Invity::Facebook::Message.new(
|
59
|
+
access_token: access_token,
|
60
|
+
sender: uid,
|
61
|
+
recievers: friends,
|
62
|
+
subject: 'Invitation',
|
63
|
+
body: "You have been invited to join http://www.example.com"
|
64
|
+
).deliver
|
65
|
+
|
66
|
+
### Available methods:
|
67
|
+
|
68
|
+
deliver == deliver to each passed recievers
|
69
|
+
deliver(:delayed) == support delayed_job gem - send as background task
|
70
|
+
deliver(:all) == deliver to all friends regardless of passed recievers
|
71
|
+
deliver(:all_delayed) == deliver to all with delayed_job gem
|
72
|
+
|
73
|
+
#### [delayed_job](https://github.com/tobi/delayed_job) gem needed for these methods:
|
74
|
+
|
75
|
+
deliver(:delayed)
|
76
|
+
deliver(:all_delayed)
|
77
|
+
|
78
|
+
[-- demo --](invity.herokuapp.com)
|
data/Rakefile
ADDED
data/invity.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'invity/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "invity"
|
8
|
+
gem.version = Invity::VERSION
|
9
|
+
gem.authors = ["Pavittar Gill"]
|
10
|
+
gem.email = ["pavittar_gill@yahoo.ca"]
|
11
|
+
gem.description = %q{Send message to facebook inbox through your rails app.}
|
12
|
+
gem.summary = %q{Send invitation through your rails app.}
|
13
|
+
gem.homepage = "https://github.com/pavittar/invity"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
|
22
|
+
gem.add_runtime_dependency('faraday' , ["0.8.7"])
|
23
|
+
gem.add_runtime_dependency('xmpp4r_facebook', ["0.1.1"])
|
24
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/invity.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Invity
|
2
|
+
module Facebook
|
3
|
+
class API
|
4
|
+
GraphUrl = 'https://graph.facebook.com'
|
5
|
+
attr_reader :access_token
|
6
|
+
attr_accessor :fields
|
7
|
+
|
8
|
+
def initialize(access_token = nil)
|
9
|
+
@access_token = access_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def friends
|
13
|
+
self.fields = 'fields=id,name'
|
14
|
+
@friends ||= response
|
15
|
+
end
|
16
|
+
|
17
|
+
def friends_with_pics
|
18
|
+
self.fields = 'fields=id,name,picture.type(small)'
|
19
|
+
@friends_with_pics ||= response
|
20
|
+
end
|
21
|
+
|
22
|
+
def friend_ids
|
23
|
+
@friend_ids ||= friends.map { |f| f['id'] }
|
24
|
+
end
|
25
|
+
|
26
|
+
private #-----------------------------------------------------
|
27
|
+
|
28
|
+
def api
|
29
|
+
@api ||=
|
30
|
+
Faraday.new(:url => GraphUrl) do |f|
|
31
|
+
f.request :url_encoded
|
32
|
+
f.response :logger
|
33
|
+
f.adapter Faraday.default_adapter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def prepare_url
|
38
|
+
"/me/friends?#{fields}&access_token=#{access_token}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def response
|
42
|
+
raise request.headers['www-authenticate'] if request.status != 200
|
43
|
+
JSON.parse( (request).body )['data']
|
44
|
+
end
|
45
|
+
|
46
|
+
def request
|
47
|
+
@request ||= api.get prepare_url
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Invity
|
2
|
+
module Facebook
|
3
|
+
class Message
|
4
|
+
attr_accessor :sender, :reciever, :recievers, :subject, :body, :access_token
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
[:sender, :recievers, :subject, :body, :access_token].each { |w|
|
8
|
+
send("#{w}=", options[w])
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform # SPECIAL METHOD USED BY DELAYED-JOBS
|
13
|
+
chat
|
14
|
+
end
|
15
|
+
|
16
|
+
def deliver(opt = nil)
|
17
|
+
case opt
|
18
|
+
when :all then deliver_all
|
19
|
+
when :all_delayed then deliver_all_as_delayed
|
20
|
+
when :delayed then deliver_as_delayed
|
21
|
+
else; deliver_each
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def deliver_all
|
26
|
+
friends.each { |f|
|
27
|
+
self.reciever = f; chat
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def deliver_all_as_delayed
|
32
|
+
friends.each { |f|
|
33
|
+
self.reciever = f
|
34
|
+
Delayed::Job.enqueue self
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def deliver_as_delayed
|
39
|
+
recievers.each { |f|
|
40
|
+
self.reciever = f
|
41
|
+
Delayed::Job.enqueue self
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def deliver_each
|
46
|
+
recievers.each { |f|
|
47
|
+
self.reciever = f; chat
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
private #--------------------------------------------
|
52
|
+
|
53
|
+
def friends
|
54
|
+
@friends ||= Invity::Facebook::API.new( access_token ).friend_ids
|
55
|
+
end
|
56
|
+
|
57
|
+
def chat
|
58
|
+
id = "-#{sender}@chat.facebook.com"
|
59
|
+
to = "-#{reciever}@chat.facebook.com"
|
60
|
+
|
61
|
+
message = Jabber::Message.new to, body
|
62
|
+
message.subject = subject
|
63
|
+
|
64
|
+
client = Jabber::Client.new Jabber::JID.new(id)
|
65
|
+
client.connect
|
66
|
+
client.auth_sasl( authenticate(client), nil)
|
67
|
+
client.send message
|
68
|
+
client.close
|
69
|
+
end
|
70
|
+
|
71
|
+
def authenticate(client)
|
72
|
+
Jabber::SASL::XFacebookPlatform.new(client,
|
73
|
+
ENV.fetch('FACEBOOK_APP_ID'), access_token, ENV.fetch('FACEBOOK_APP_SECRET')
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/.DS_Store
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'invity'
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: invity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pavittar Gill
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.8.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.7
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: xmpp4r_facebook
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.1.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.1
|
62
|
+
description: Send message to facebook inbox through your rails app.
|
63
|
+
email:
|
64
|
+
- pavittar_gill@yahoo.ca
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .DS_Store
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- CHANGELOG.md
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- invity.gemspec
|
78
|
+
- lib/.DS_Store
|
79
|
+
- lib/invity.rb
|
80
|
+
- lib/invity/facebook.rb
|
81
|
+
- lib/invity/message.rb
|
82
|
+
- lib/invity/version.rb
|
83
|
+
- spec/.DS_Store
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/pavittar/invity
|
86
|
+
licenses: []
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.24
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Send invitation through your rails app.
|
109
|
+
test_files:
|
110
|
+
- spec/.DS_Store
|
111
|
+
- spec/spec_helper.rb
|