Class: MessageQuickly::Api::Messages

Inherits:
Base
  • Object
show all
Defined in:
lib/message_quickly/api/messages.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, #initialize

Constructor Details

This class inherits a constructor from MessageQuickly::Api::Base

Class Method Details

.create(recipient = nil, delivery = nil, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/message_quickly/api/messages.rb', line 5

def self.create(recipient = nil, delivery = nil, &block)
  # curl -X POST -H "Content-Type: application/json" -d '{
  #   "recipient":{
  #       "id":"USER_ID"
  #   },
  #   "message":{
  #       "text":"hello, world!"
  #   }
  # }' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

  # {
  #   "recipient_id": "1008372609250235",
  #   "message_id": "mid.1456970487936:c34767dfe57ee6e339"
  # }
  Messages.new.create(recipient, delivery, &block)
end

.create_from_hash(hash) ⇒ Object



29
30
31
# File 'lib/message_quickly/api/messages.rb', line 29

def self.create_from_hash(hash)
  Messages.new.create_from_hash(hash)
end

Instance Method Details

#create(recipient = nil, delivery = nil, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/message_quickly/api/messages.rb', line 22

def create(recipient = nil, delivery = nil, &block)
  delivery ||= MessageQuickly::Messaging::Delivery.new(recipient: recipient)
  block.call(delivery.message) if block
  delivery.id = perform_call(delivery.to_hash)
  delivery
end

#create_from_hash(hash) ⇒ Object



33
34
35
# File 'lib/message_quickly/api/messages.rb', line 33

def create_from_hash(hash)
  perform_call(hash)
end