messenger_client 0.1.7 → 0.1.8

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: 5be3656412b5664d59d1b95d989cdc4de95f0585
4
- data.tar.gz: 6ca13b5dd6e49cba684ba1e4ae4a8bb3cab315ed
3
+ metadata.gz: ff07568123e58ad73684f2dce0b4026553cad618
4
+ data.tar.gz: b37605c98b827b030002682eef0833bb1850e0d0
5
5
  SHA512:
6
- metadata.gz: cd853bea2c37fcf5c9fa27a027ca50b241debc61346ca8e57a8bf8b88a8febdb81f09af577de9d135ebbed75dca2ef1e7cf29ee52ceba38df0f8adaccd3d8ce9
7
- data.tar.gz: f5a3e0247221b094bc548b3fbb2e571552f8f72fbe202db2871b006bee481155872d31edc206723829f74dd85d95fd9d95a7781fc1c219714f1e7ccae1f9d672
6
+ metadata.gz: ef412c0646b4ca7f976b034c52931be12cdc60ba1c17082c5ec7c50877e9df168ed14d4d8fda69ade4e18cf7c808795e5097adf66e01e574e1702ed6df4679bb
7
+ data.tar.gz: 6da52d83c5638e13bd721f384719f75ca1f5deaf58f6785d2f0dee77b9513c60c155bb7191c4ed5698fde165b5591c12a7f8f1d2617f5d7ac2b606f00a254909
@@ -1,20 +1,15 @@
1
1
  module MessengerClient
2
2
  class Client
3
- URL_TEMPLATE = "https://graph.facebook.com/v2.6/me/messages?access_token=%s"
3
+ URL_TEMPLATE = "https://graph.facebook.com/v2.6/me/%s"
4
4
 
5
5
  def initialize(page_access_token)
6
6
  @page_access_token = page_access_token
7
7
  @logger = MessengerClient::Config.logger
8
8
  end
9
9
 
10
- def setup_menu(buttons)
11
- menu = Menu.new(buttons)
12
- post(menu.to_json)
13
- end
14
-
15
10
  def get_started(postback="get_started")
16
11
  gs = GetStarted.new(postback)
17
- post(gs.to_json)
12
+ profile_post(gs.to_json)
18
13
  end
19
14
 
20
15
  def text(recipient_id:, text:)
@@ -83,8 +78,8 @@ module MessengerClient
83
78
  }
84
79
  payload.merge!(message: data) unless data.nil?
85
80
  payload.merge!(opts)
86
- res = Typhoeus.post(url, body: json(payload), headers: headers)
87
- @logger.debug(url) if ENV["DEBUG"]
81
+ res = Typhoeus.post(message_url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
82
+ @logger.debug(message_url) if ENV["DEBUG"]
88
83
  @logger.debug(json(payload)) if ENV["DEBUG"]
89
84
  @logger.debug(res.body) if ENV["DEBUG"]
90
85
  @logger.debug(res.headers) if ENV["DEBUG"]
@@ -92,8 +87,17 @@ module MessengerClient
92
87
  end
93
88
 
94
89
  def post(payload)
95
- res = Typhoeus.post(url, body: json(payload), headers: headers)
96
- @logger.debug(url) if ENV["DEBUG"]
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"]
92
+ @logger.debug(json(payload)) if ENV["DEBUG"]
93
+ @logger.debug(res.body) if ENV["DEBUG"]
94
+ @logger.debug(res.headers) if ENV["DEBUG"]
95
+ res
96
+ end
97
+
98
+ def profile_post(payload)
99
+ res = Typhoeus.post(profile_url, body: json(payload), params: { access_token: @page_access_token }, headers: headers)
100
+ @logger.debug(profile_url) if ENV["DEBUG"]
97
101
  @logger.debug(json(payload)) if ENV["DEBUG"]
98
102
  @logger.debug(res.body) if ENV["DEBUG"]
99
103
  @logger.debug(res.headers) if ENV["DEBUG"]
@@ -102,8 +106,12 @@ module MessengerClient
102
106
 
103
107
  private
104
108
 
105
- def url
106
- URL_TEMPLATE % @page_access_token
109
+ def message_url
110
+ URL_TEMPLATE % "messages"
111
+ end
112
+
113
+ def profile_url
114
+ URL_TEMPLATE % "messenger_profile"
107
115
  end
108
116
 
109
117
  def json(payload)
@@ -112,7 +120,7 @@ module MessengerClient
112
120
 
113
121
  def headers
114
122
  { 'Accept-Encoding' => 'application/json',
115
- 'Content-Type' => 'application/json' }
123
+ 'Content-Type' => 'application/json' }
116
124
  end
117
125
  end
118
126
  end
@@ -20,5 +20,3 @@ module MessengerClient
20
20
  end
21
21
  end
22
22
  end
23
-
24
-
@@ -1,3 +1,3 @@
1
1
  module MessengerClient
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messenger_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Cruz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-02 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler