Skip to content

Commit

Permalink
Merge pull request #55 from dmitryshagin/master
Browse files Browse the repository at this point in the history
Slight refactoring to increase code climate
  • Loading branch information
jgorset committed Aug 12, 2016
2 parents f86e420 + 5d7af51 commit dce93b0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion facebook-messenger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_runtime_dependency 'httparty', '~> 0.13.7'
spec.add_runtime_dependency 'httparty', '~> 0.13', '>= 0.13.7'
spec.add_runtime_dependency 'rack', '>= 1.6.4'

spec.add_development_dependency 'bundler', '~> 1.11'
Expand Down
26 changes: 26 additions & 0 deletions lib/facebook/messenger/concerns/default_options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Facebook
module Messenger
module Concerns
# The Common options for incoming optin and postback.
module DefaultOptions
attr_reader :messaging

def initialize(messaging)
@messaging = messaging
end

def sender
@messaging['sender']
end

def recipient
@messaging['recipient']
end

def sent_at
Time.at(@messaging['timestamp'] / 1000)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/facebook/messenger/incoming.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'facebook/messenger/concerns/default_options'
require 'facebook/messenger/incoming/message'
require 'facebook/messenger/incoming/delivery'
require 'facebook/messenger/incoming/postback'
Expand Down
18 changes: 1 addition & 17 deletions lib/facebook/messenger/incoming/optin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@ module Incoming
#
# https://developers.facebook.com/docs/messenger-platform/plugin-reference
class Optin
attr_reader :messaging

def initialize(messaging)
@messaging = messaging
end

def sender
@messaging['sender']
end

def recipient
@messaging['recipient']
end

def sent_at
Time.at(@messaging['timestamp'] / 1000)
end
include Facebook::Messenger::Concerns::DefaultOptions

def ref
@messaging['optin']['ref']
Expand Down
18 changes: 1 addition & 17 deletions lib/facebook/messenger/incoming/postback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@ module Messenger
module Incoming
# The Postback class represents an incoming Facebook Messenger postback.
class Postback
attr_reader :messaging

def initialize(messaging)
@messaging = messaging
end

def sender
@messaging['sender']
end

def recipient
@messaging['recipient']
end

def sent_at
Time.at(@messaging['timestamp'] / 1000)
end
include Facebook::Messenger::Concerns::DefaultOptions

def payload
@messaging['postback']['payload']
Expand Down

0 comments on commit dce93b0

Please sign in to comment.