ruboty-hibari_bento 0.0.4 → 0.0.5

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: 49a2f76be7bae7f2a12f940d508775ce5b3f442c
4
- data.tar.gz: 1d036062c372f44615a08013c8ee4a31138f8115
3
+ metadata.gz: ba12630db16119fd6821cf2319f9772e48846f27
4
+ data.tar.gz: a5df4797695369a0d5e7a016e5729abf40b5aaf8
5
5
  SHA512:
6
- metadata.gz: 27867ca919a8ba522705ee851a3c48ec10e42f6939d60f037fc330ac2f485da02176dacb70e9d25f13482bba70ccace32e392b5dca887083babaab4bb530efaa
7
- data.tar.gz: e725658d7e18af0aca6d9d0fab0508addbaaa5ec74533b88133158cd9d4e012879f9d1008fd33627e269226b664baa93f4124fa867ed1c890e4130b6bbae029d
6
+ metadata.gz: 8b568a4b4f5af2f97a235f1a9d1abe2a981e8ca5d81f696cb9cb5530a89150ae44eb53ec4326dcf971e274720feec5b73a91188c570ef678516a0bc85cfc9f64
7
+ data.tar.gz: c9b3d9c592cc452d19c24d54b633e3b87e745ab5aae8710265b5b1393ce0a82373c49813c035f40a69d33c00e612fd8a050e114b4ab9fa833c6e60585f171353
@@ -2,8 +2,8 @@ module Ruboty
2
2
  module HibariBento
3
3
  module Actions
4
4
  class Pull < Ruboty::Actions::Base
5
+ FACEBOOK_URL = 'https://www.facebook.com'.freeze
5
6
  FACEBOOK_PAGE_ID = '1585734291650119'.freeze
6
- FACEBOOK_GRAPH_API_URL = 'https://graph.facebook.com'.freeze
7
7
  REDIS_NAMESPACE = 'hibari_bento'.freeze
8
8
  REDIS_KEY = 'id'.freeze
9
9
 
@@ -27,7 +27,7 @@ module Ruboty
27
27
 
28
28
  def posts
29
29
  options = {
30
- fields: %w(id object_id link message updated_time),
30
+ fields: %w(id attachments message updated_time),
31
31
  locale: 'ja_JP'
32
32
  }
33
33
  return graph.get_connections(FACEBOOK_PAGE_ID, 'posts', options)
@@ -80,8 +80,8 @@ module Ruboty
80
80
  def message_content(post)
81
81
  messages = []
82
82
  messages.push(post['message'])
83
- messages.push(picture_url(post['object_id']))
84
- messages.push(post['link'])
83
+ messages.push(photo_urls(post))
84
+ messages.push(post_url(post['id']))
85
85
  messages.compact!
86
86
  messages.reject!(&:empty?)
87
87
 
@@ -92,9 +92,27 @@ module Ruboty
92
92
  return messages.join("\n")
93
93
  end
94
94
 
95
- def picture_url(object_id)
96
- return '' if object_id.nil?
97
- return "#{FACEBOOK_GRAPH_API_URL}/#{object_id}/picture"
95
+ def photo_urls(post)
96
+ urls = []
97
+
98
+ post['attachments']['data'].each do |attachment|
99
+ subattachments = attachment['subattachments']
100
+ if subattachments.nil?
101
+ urls.push(attachment['media']['image']['src'])
102
+ else
103
+ subattachments['data'].each do |subattachment|
104
+ urls.push(subattachment['media']['image']['src'])
105
+ end
106
+ end
107
+ end
108
+
109
+ return urls.join("\n")
110
+ end
111
+
112
+ def post_url(post_id)
113
+ id = post_id.split('_')[1]
114
+ return "" if id.nil?
115
+ return "#{FACEBOOK_URL}/#{FACEBOOK_PAGE_ID}/posts/#{id}"
98
116
  end
99
117
 
100
118
  def time_format(time)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module HibariBento
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -1,8 +1,32 @@
1
1
  {
2
2
  "data":[
3
3
  {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
4
+ "id":"6543210987654321_1234567890123456",
5
+ "attachments":{
6
+ "data":[
7
+ {
8
+ "subattachments":{
9
+ "data":[
10
+ {
11
+ "media":{
12
+ "image":{
13
+ "height":640,
14
+ "src":"https://example.net/test/image.jpg?foo=1234abcd&bar=1234abcd",
15
+ "width":640
16
+ }
17
+ },
18
+ "target":{
19
+ "id":"2345678901234567",
20
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
21
+ },
22
+ "type":"photo",
23
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ ]
29
+ },
6
30
  "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
31
  "message":"こんにちは!\n新規配達先受付中!",
8
32
  "updated_time":"2015-02-19T23:30:05+0000"
@@ -1,8 +1,32 @@
1
1
  {
2
2
  "data":[
3
3
  {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
4
+ "id":"6543210987654321_1234567890123456",
5
+ "attachments":{
6
+ "data":[
7
+ {
8
+ "subattachments":{
9
+ "data":[
10
+ {
11
+ "media":{
12
+ "image":{
13
+ "height":640,
14
+ "src":"https://example.net/test/image.jpg?foo=1234abcd&bar=1234abcd",
15
+ "width":640
16
+ }
17
+ },
18
+ "target":{
19
+ "id":"2345678901234567",
20
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
21
+ },
22
+ "type":"photo",
23
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ ]
29
+ },
6
30
  "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
31
  "message":"",
8
32
  "updated_time":"2015-02-19T23:30:05+0000"
@@ -1,8 +1,32 @@
1
1
  {
2
2
  "data":[
3
3
  {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
4
+ "id":"6543210987654321_1234567890123456",
5
+ "attachments":{
6
+ "data":[
7
+ {
8
+ "subattachments":{
9
+ "data":[
10
+ {
11
+ "media":{
12
+ "image":{
13
+ "height":640,
14
+ "src":"https://example.net/test/image.jpg?foo=1234abcd&bar=1234abcd",
15
+ "width":640
16
+ }
17
+ },
18
+ "target":{
19
+ "id":"2345678901234567",
20
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
21
+ },
22
+ "type":"photo",
23
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ ]
29
+ },
6
30
  "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
31
  "updated_time":"2015-02-19T23:30:05+0000"
8
32
  }
@@ -1,15 +1,73 @@
1
1
  {
2
2
  "data":[
3
3
  {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
4
+ "id":"6543210987654321_1234567890123456",
5
+ "attachments":{
6
+ "data":[
7
+ {
8
+ "media":{
9
+ "image":{
10
+ "height":640,
11
+ "src":"https://example.net/test/image.jpg?foo=1234abcd&bar=1234abcd",
12
+ "width":640
13
+ }
14
+ },
15
+ "target":{
16
+ "id":"2345678901234567",
17
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
18
+ },
19
+ "title":"ひばり弁当さんのカバー写真",
20
+ "type":"photo",
21
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
22
+ }
23
+ ]
24
+ },
6
25
  "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
7
26
  "message":"こんにちは!\n新規配達先受付中!",
8
27
  "updated_time":"2015-02-19T23:30:05+0000"
9
28
  },
10
29
  {
11
- "id":"9876543210987654",
12
- "object_id":"8765432109876543",
30
+ "id":"4567890123456789_9876543210987654",
31
+ "attachments":{
32
+ "data":[
33
+ {
34
+ "subattachments":{
35
+ "data":[
36
+ {
37
+ "media":{
38
+ "image":{
39
+ "height":640,
40
+ "src":"https://example.net/test/image.jpg?foo=1234abcd&bar=1234abcd",
41
+ "width":640
42
+ }
43
+ },
44
+ "target":{
45
+ "id":"4567890123456789",
46
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
47
+ },
48
+ "type":"photo",
49
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
50
+ },
51
+ {
52
+ "media":{
53
+ "image":{
54
+ "height":640,
55
+ "src":"https://example.net/test/image.png?foo=5678efgh&bar=5678efgh",
56
+ "width":640
57
+ }
58
+ },
59
+ "target":{
60
+ "id":"5678901234567890",
61
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
62
+ },
63
+ "type":"photo",
64
+ "url":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1"
65
+ }
66
+ ]
67
+ }
68
+ }
69
+ ]
70
+ },
13
71
  "link":"https:\/\/www.facebook.com\/9876543210987654\/photos\/a.3456789012345678.1234567890.9876543210987654\/8765432109876543\/?type=1",
14
72
  "message":"本日のお昼の弁当です。\nおかずのみ350円・ご飯250gとセットで440円。",
15
73
  "updated_time":"2015-02-18T23:50:10+0000"
@@ -13,30 +13,29 @@ describe Ruboty::HibariBento::Actions::Pull do
13
13
  let(:pull) { Ruboty::HibariBento::Actions::Pull.new(message) }
14
14
 
15
15
  describe 'reply message' do
16
- let(:facebook_graph_api_url) { Ruboty::HibariBento::Actions::Pull::FACEBOOK_GRAPH_API_URL }
17
- let(:request_url) { "#{facebook_graph_api_url}/#{Ruboty::HibariBento::Actions::Pull::FACEBOOK_PAGE_ID}/posts" }
16
+ let(:page_id) { Ruboty::HibariBento::Actions::Pull::FACEBOOK_PAGE_ID }
17
+ let(:request_url) { "https://graph.facebook.com/#{page_id}/posts" }
18
18
  let(:access_token) { 'token' }
19
19
  let(:request_query) do
20
20
  {
21
21
  access_token: access_token,
22
- fields: 'id,object_id,link,message,updated_time',
22
+ fields: 'id,attachments,message,updated_time',
23
23
  locale: 'ja_JP'
24
24
  }
25
25
  end
26
26
 
27
27
  let(:post_id) { '1234567890123456' }
28
- let(:post_object_id) { '2345678901234567' }
29
28
  let(:expected_message) { /こんにちは!\n新規配達先受付中!/ }
30
- let(:expected_picture_url) { Regexp.new(Regexp.escape("#{facebook_graph_api_url}/#{post_object_id}/picture")) }
31
- let(:expected_link) { Regexp.new(Regexp.escape("https://www.facebook.com/#{post_id}/photos/a.3456789012345678.1234567890.#{post_id}/#{post_object_id}/?type=1")) }
29
+ let(:photo_url_regexp) { 'https:\/\/.+\.(jpg|jpeg|png|gif).*' }
30
+ let(:expected_photo_urls) { Regexp.new(photo_url_regexp) }
31
+ let(:expected_post_url) { Regexp.new(Regexp.escape("#{Ruboty::HibariBento::Actions::Pull::FACEBOOK_URL}\/#{page_id}\/posts\/#{post_id}")) }
32
32
  let(:expected_updated_time) { /2015-02-20 08:30:05/ }
33
33
  let(:expected_separator) { /\n--------------------\n/ }
34
34
 
35
35
  let(:post_id_2) { '9876543210987654' }
36
- let(:post_object_id_2) { '8765432109876543' }
37
36
  let(:expected_message_2) { /本日のお昼の弁当です。\nおかずのみ350円・ご飯250gとセットで440円。/ }
38
- let(:expected_picture_url_2) { Regexp.new(Regexp.escape("#{facebook_graph_api_url}/#{post_object_id_2}/picture")) }
39
- let(:expected_link_2) { Regexp.new(Regexp.escape("https://www.facebook.com/#{post_id_2}/photos/a.3456789012345678.1234567890.#{post_id_2}/#{post_object_id_2}/?type=1")) }
37
+ let(:expected_photo_urls_2) { Regexp.new("#{photo_url_regexp}\\n#{photo_url_regexp}") }
38
+ let(:expected_post_url_2) { Regexp.new(Regexp.escape("#{Ruboty::HibariBento::Actions::Pull::FACEBOOK_URL}\/#{page_id}\/posts\/#{post_id_2}")) }
40
39
  let(:expected_updated_time_2) { /2015-02-19 08:50:10/ }
41
40
 
42
41
  before do
@@ -54,8 +53,8 @@ describe Ruboty::HibariBento::Actions::Pull do
54
53
  end
55
54
 
56
55
  it { is_expected.to match(expected_message) }
57
- it { is_expected.to match(expected_picture_url) }
58
- it { is_expected.to match(expected_link) }
56
+ it { is_expected.to match(expected_photo_urls) }
57
+ it { is_expected.to match(expected_post_url) }
59
58
  it { is_expected.to match(expected_updated_time) }
60
59
  it { is_expected.not_to match(expected_separator) }
61
60
  end
@@ -68,8 +67,8 @@ describe Ruboty::HibariBento::Actions::Pull do
68
67
  end
69
68
 
70
69
  it { is_expected.not_to match(expected_message) }
71
- it { is_expected.to match(expected_picture_url) }
72
- it { is_expected.to match(expected_link) }
70
+ it { is_expected.to match(expected_photo_urls) }
71
+ it { is_expected.to match(expected_post_url) }
73
72
  it { is_expected.to match(expected_updated_time) }
74
73
  it { is_expected.not_to match(expected_separator) }
75
74
  end
@@ -82,50 +81,8 @@ describe Ruboty::HibariBento::Actions::Pull do
82
81
  end
83
82
 
84
83
  it { is_expected.not_to match(expected_message) }
85
- it { is_expected.to match(expected_picture_url) }
86
- it { is_expected.to match(expected_link) }
87
- it { is_expected.to match(expected_updated_time) }
88
- it { is_expected.not_to match(expected_separator) }
89
- end
90
-
91
- context 'with no object_id' do
92
- before do
93
- stub_request(:get, request_url)
94
- .with(query: request_query)
95
- .to_return(body: File.new('spec/fixtures/a_post_with_no_object_id.json'), status: 200)
96
- end
97
-
98
- it { is_expected.to match(expected_message) }
99
- it { is_expected.not_to match(expected_picture_url) }
100
- it { is_expected.to match(expected_link) }
101
- it { is_expected.to match(expected_updated_time) }
102
- it { is_expected.not_to match(expected_separator) }
103
- end
104
-
105
- context 'with no link' do
106
- before do
107
- stub_request(:get, request_url)
108
- .with(query: request_query)
109
- .to_return(body: File.new('spec/fixtures/a_post_with_no_link.json'), status: 200)
110
- end
111
-
112
- it { is_expected.to match(expected_message) }
113
- it { is_expected.to match(expected_picture_url) }
114
- it { is_expected.not_to match(expected_link) }
115
- it { is_expected.to match(expected_updated_time) }
116
- it { is_expected.not_to match(expected_separator) }
117
- end
118
-
119
- context 'with empty link' do
120
- before do
121
- stub_request(:get, request_url)
122
- .with(query: request_query)
123
- .to_return(body: File.new('spec/fixtures/a_post_with_empty_link.json'), status: 200)
124
- end
125
-
126
- it { is_expected.to match(expected_message) }
127
- it { is_expected.to match(expected_picture_url) }
128
- it { is_expected.not_to match(expected_link) }
84
+ it { is_expected.to match(expected_photo_urls) }
85
+ it { is_expected.to match(expected_post_url) }
129
86
  it { is_expected.to match(expected_updated_time) }
130
87
  it { is_expected.not_to match(expected_separator) }
131
88
  end
@@ -140,13 +97,13 @@ describe Ruboty::HibariBento::Actions::Pull do
140
97
  end
141
98
 
142
99
  it { is_expected.to match(expected_message) }
143
- it { is_expected.to match(expected_picture_url) }
144
- it { is_expected.to match(expected_link) }
100
+ it { is_expected.to match(expected_photo_urls) }
101
+ it { is_expected.to match(expected_post_url) }
145
102
  it { is_expected.to match(expected_updated_time) }
146
103
  it { is_expected.to match(expected_separator) }
147
104
  it { is_expected.to match(expected_message_2) }
148
- it { is_expected.to match(expected_picture_url_2) }
149
- it { is_expected.to match(expected_link_2) }
105
+ it { is_expected.to match(expected_photo_urls_2) }
106
+ it { is_expected.to match(expected_post_url_2) }
150
107
  it { is_expected.to match(expected_updated_time_2) }
151
108
  end
152
109
  end
@@ -160,13 +117,13 @@ describe Ruboty::HibariBento::Actions::Pull do
160
117
  end
161
118
 
162
119
  it { is_expected.to match(expected_message) }
163
- it { is_expected.to match(expected_picture_url) }
164
- it { is_expected.to match(expected_link) }
120
+ it { is_expected.to match(expected_photo_urls) }
121
+ it { is_expected.to match(expected_post_url) }
165
122
  it { is_expected.to match(expected_updated_time) }
166
123
  it { is_expected.not_to match(expected_separator) }
167
124
  it { is_expected.not_to match(expected_message_2) }
168
- it { is_expected.not_to match(expected_picture_url_2) }
169
- it { is_expected.not_to match(expected_link_2) }
125
+ it { is_expected.not_to match(expected_photo_urls_2) }
126
+ it { is_expected.not_to match(expected_post_url_2) }
170
127
  it { is_expected.not_to match(expected_updated_time_2) }
171
128
  end
172
129
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-hibari_bento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Enjo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-21 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -169,11 +169,8 @@ files:
169
169
  - lib/ruboty/hibari_bento/version.rb
170
170
  - ruboty-hibari_bento.gemspec
171
171
  - spec/fixtures/a_post_with_all_fields.json
172
- - spec/fixtures/a_post_with_empty_link.json
173
172
  - spec/fixtures/a_post_with_empty_message.json
174
- - spec/fixtures/a_post_with_no_link.json
175
173
  - spec/fixtures/a_post_with_no_message.json
176
- - spec/fixtures/a_post_with_no_object_id.json
177
174
  - spec/fixtures/no_posts.json
178
175
  - spec/fixtures/some_posts_with_all_fields.json
179
176
  - spec/ruboty/handlers/hibari_bento_spec.rb
@@ -206,11 +203,8 @@ summary: Ruboty handler to get information of Hibari Bento, the bento shop in Ru
206
203
  City MATSUE.
207
204
  test_files:
208
205
  - spec/fixtures/a_post_with_all_fields.json
209
- - spec/fixtures/a_post_with_empty_link.json
210
206
  - spec/fixtures/a_post_with_empty_message.json
211
- - spec/fixtures/a_post_with_no_link.json
212
207
  - spec/fixtures/a_post_with_no_message.json
213
- - spec/fixtures/a_post_with_no_object_id.json
214
208
  - spec/fixtures/no_posts.json
215
209
  - spec/fixtures/some_posts_with_all_fields.json
216
210
  - spec/ruboty/handlers/hibari_bento_spec.rb
@@ -1,11 +0,0 @@
1
- {
2
- "data":[
3
- {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
6
- "link":"",
7
- "message":"こんにちは!\n新規配達先受付中!",
8
- "updated_time":"2015-02-19T23:30:05+0000"
9
- }
10
- ]
11
- }
@@ -1,10 +0,0 @@
1
- {
2
- "data":[
3
- {
4
- "id":"1234567890123456",
5
- "object_id":"2345678901234567",
6
- "message":"こんにちは!\n新規配達先受付中!",
7
- "updated_time":"2015-02-19T23:30:05+0000"
8
- }
9
- ]
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "data":[
3
- {
4
- "id":"1234567890123456",
5
- "link":"https:\/\/www.facebook.com\/1234567890123456\/photos\/a.3456789012345678.1234567890.1234567890123456\/2345678901234567\/?type=1",
6
- "message":"こんにちは!\n新規配達先受付中!",
7
- "updated_time":"2015-02-19T23:30:05+0000"
8
- }
9
- ]
10
- }