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: ff07568123e58ad73684f2dce0b4026553cad618
4
- data.tar.gz: b37605c98b827b030002682eef0833bb1850e0d0
3
+ metadata.gz: 7f5ef9c12dbe6709e46d6f0932553857f20a6e03
4
+ data.tar.gz: dee5f67cf8a8128c83859c3901ed1cef55959a14
5
5
  SHA512:
6
- metadata.gz: ef412c0646b4ca7f976b034c52931be12cdc60ba1c17082c5ec7c50877e9df168ed14d4d8fda69ade4e18cf7c808795e5097adf66e01e574e1702ed6df4679bb
7
- data.tar.gz: 6da52d83c5638e13bd721f384719f75ca1f5deaf58f6785d2f0dee77b9513c60c155bb7191c4ed5698fde165b5591c12a7f8f1d2617f5d7ac2b606f00a254909
6
+ metadata.gz: 7547a12ad611c4aa5615733907691ae1bd3e83126e16ec66337d02d25faecdb856448d00fcb8b68d485b1f2ceab9e239d90bb1fbec65c2ed1ef499103bcfc6df
7
+ data.tar.gz: '035496b29a94129f3156ed97ad59a9774b32c063716d13816e7d4fe1f0e2130bd0146effc80e76d2bef1c9df6429226d71a0c0a41cf44963509841ac47653107'
@@ -1,17 +1,35 @@
1
1
  module MessengerClient
2
2
  class Client
3
- URL_TEMPLATE = "https://graph.facebook.com/v2.6/me/%s"
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 get_started(postback="get_started")
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) if ENV["DEBUG"]
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(message_url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
91
- @logger.debug(message_url) if ENV["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
@@ -6,13 +6,9 @@ module MessengerClient
6
6
 
7
7
  def to_json
8
8
  {
9
- setting_type: "call_to_actions",
10
- thread_state: "new_thread",
11
- call_to_actions: [
12
- {
13
- payload: @postback
14
- }
15
- ]
9
+ get_started: {
10
+ payload: @postback
11
+ }
16
12
  }
17
13
  end
18
14
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module MessengerClient
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -12,6 +12,10 @@ require "messenger_client/message_parser"
12
12
  # Config
13
13
  require "messenger_client/config"
14
14
 
15
+ # Profile
16
+
17
+ require "messenger_client/profile"
18
+
15
19
  # Buttons
16
20
  require "messenger_client/button"
17
21
  require "messenger_client/call_button"
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.8
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