messenger_client 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f5ef9c12dbe6709e46d6f0932553857f20a6e03
|
4
|
+
data.tar.gz: dee5f67cf8a8128c83859c3901ed1cef55959a14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7547a12ad611c4aa5615733907691ae1bd3e83126e16ec66337d02d25faecdb856448d00fcb8b68d485b1f2ceab9e239d90bb1fbec65c2ed1ef499103bcfc6df
|
7
|
+
data.tar.gz: '035496b29a94129f3156ed97ad59a9774b32c063716d13816e7d4fe1f0e2130bd0146effc80e76d2bef1c9df6429226d71a0c0a41cf44963509841ac47653107'
|
@@ -1,17 +1,35 @@
|
|
1
1
|
module MessengerClient
|
2
2
|
class Client
|
3
|
-
|
3
|
+
URL_BASE = "https://graph.facebook.com/v2.6/%s"
|
4
|
+
URL_TEMPLATE = URL_BASE % "me/%s"
|
4
5
|
|
5
6
|
def initialize(page_access_token)
|
6
7
|
@page_access_token = page_access_token
|
7
8
|
@logger = MessengerClient::Config.logger
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
+
def set_get_started(postback="get_started")
|
11
12
|
gs = GetStarted.new(postback)
|
12
13
|
profile_post(gs.to_json)
|
13
14
|
end
|
14
15
|
|
16
|
+
def delete_get_started
|
17
|
+
payload = { fields: ["get_started"] }
|
18
|
+
delete(profile_url, payload)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_persistent_menu
|
22
|
+
payload = { fields: ["persistent_menu"] }
|
23
|
+
delete(profile_url, payload)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_profile(facebook_id:, scopes:)
|
27
|
+
scope_list = scopes.join(",")
|
28
|
+
query = { fields: scope_list }
|
29
|
+
url = URL_BASE % facebook_id
|
30
|
+
get(url, query)
|
31
|
+
end
|
32
|
+
|
15
33
|
def text(recipient_id:, text:)
|
16
34
|
send(recipient_id, text: text)
|
17
35
|
end
|
@@ -79,16 +97,16 @@ module MessengerClient
|
|
79
97
|
payload.merge!(message: data) unless data.nil?
|
80
98
|
payload.merge!(opts)
|
81
99
|
res = Typhoeus.post(message_url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
|
82
|
-
@logger.debug(message_url)
|
100
|
+
@logger.debug(message_url) if ENV["DEBUG"]
|
83
101
|
@logger.debug(json(payload)) if ENV["DEBUG"]
|
84
102
|
@logger.debug(res.body) if ENV["DEBUG"]
|
85
103
|
@logger.debug(res.headers) if ENV["DEBUG"]
|
86
104
|
res
|
87
105
|
end
|
88
106
|
|
89
|
-
def post(payload)
|
90
|
-
res = Typhoeus.post(
|
91
|
-
@logger.debug(
|
107
|
+
def post(payload, url = message_url)
|
108
|
+
res = Typhoeus.post(url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
|
109
|
+
@logger.debug(url) if ENV["DEBUG"]
|
92
110
|
@logger.debug(json(payload)) if ENV["DEBUG"]
|
93
111
|
@logger.debug(res.body) if ENV["DEBUG"]
|
94
112
|
@logger.debug(res.headers) if ENV["DEBUG"]
|
@@ -104,6 +122,25 @@ module MessengerClient
|
|
104
122
|
res
|
105
123
|
end
|
106
124
|
|
125
|
+
def get(url, query = {})
|
126
|
+
res = Typhoeus.get(url, params: { access_token: @page_access_token }.merge(query), headers: headers)
|
127
|
+
if res.success?
|
128
|
+
JSON.load(res.body)
|
129
|
+
else
|
130
|
+
@logger.error("GET Request to #{url} with query #{query.inspect} Failed with #{res.code}")
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def delete(url, payload)
|
136
|
+
res = Typhoeus.delete(url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
|
137
|
+
@logger.debug(url) if ENV["DEBUG"]
|
138
|
+
@logger.debug(json(payload)) if ENV["DEBUG"]
|
139
|
+
@logger.debug(res.body) if ENV["DEBUG"]
|
140
|
+
@logger.debug(res.headers) if ENV["DEBUG"]
|
141
|
+
res
|
142
|
+
end
|
143
|
+
|
107
144
|
private
|
108
145
|
|
109
146
|
def message_url
|
File without changes
|
data/lib/messenger_client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messenger_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Cruz
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/messenger_client/message/video.rb
|
112
112
|
- lib/messenger_client/message_parser.rb
|
113
113
|
- lib/messenger_client/payload_button.rb
|
114
|
+
- lib/messenger_client/profile.rb
|
114
115
|
- lib/messenger_client/quick_replies.rb
|
115
116
|
- lib/messenger_client/quick_reply.rb
|
116
117
|
- lib/messenger_client/share_button.rb
|