fabychy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3ef24822b7befc7c0557b46425d64d74f76929d
4
+ data.tar.gz: f598182235c89ae306c95d79dadd7f84b055b70b
5
+ SHA512:
6
+ metadata.gz: 6402ac7b3dde3a7191da382459ca27ca448c1dd12a532da1ce83f11c35fe218fc53330cf8e7ed80bedfdbd08a3c7d41a06bb188ede39f6118cc8858d68d40216
7
+ data.tar.gz: f6d21e92eaeb13258323bd60e4a0d603ad21032f3b8712e513d3423ef314f7e2cc4d31e8c6df883ecc52e066d2399c5427e7ce4832824a4477572adeddb883b7
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /db/*.sqlite3
7
+ /db/*.sqlite3-journal
8
+ /public/system
9
+ /coverage/
10
+ /spec/tmp
11
+ **.orig
12
+ rerun.txt
13
+ pickle-email-*.html
14
+
15
+ # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
16
+ config/initializers/secret_token.rb
17
+ config/secrets.yml
18
+
19
+ ## Environment normalization:
20
+ /.bundle
21
+ /vendor/bundle
22
+
23
+ # these should all be checked in to normalize the environment:
24
+ # Gemfile.lock, .ruby-version, .ruby-gemset
25
+
26
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
27
+ .rvmrc
28
+
29
+ # if using bower-rails ignore default bower_components path bower.json files
30
+ /vendor/assets/bower_components
31
+ *.bowerrc
32
+ bower.json
33
+
34
+ # Ignore pow environment settings
35
+ .powenv
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nima Kaviani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
File without changes
data/fabychy.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'fabychy/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fabychy"
7
+ spec.version = Fabychy::VERSION
8
+ spec.authors = ["Nima Kaviani"]
9
+ spec.email = ["nima@robochy.com"]
10
+ spec.description = %q{Ruby client for Facebook Bot API}
11
+ spec.summary = %q{Ruby client for Facebook Bot API}
12
+ spec.homepage = "https://github.com/nkaviani/fabychy"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "httpclient", "~> 2.6"
21
+ spec.add_dependency "virtus", "~> 1.0"
22
+ spec.add_dependency "multi_json", "~> 1.11"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.1"
26
+ end
@@ -0,0 +1,34 @@
1
+ module Fabychy
2
+ class ApiResponse
3
+ attr_reader :body
4
+ attr_reader :result
5
+ attr_reader :success
6
+
7
+ def initialize(response,fail_silently = false)
8
+ if response.status < 500
9
+ @body = response.body
10
+ data = MultiJson.load(@body)
11
+ @success = (response.status == 200)
12
+
13
+ if @success
14
+ @result = data
15
+ else
16
+ if !fail_silently
17
+ fail Fabychy::Errors::BadRequestError.new(data['error'], data['message'])
18
+ end
19
+ end
20
+ else
21
+ if !fail_silently
22
+ fail Fabychy::Errors::ServiceUnavailableError.new(response.status)
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.parse(request)
28
+ Fabychy::DataTypes::ReceivedMessages.new(MultiJson.load(request.body))
29
+ end
30
+
31
+ alias_method :success?, :success
32
+ end
33
+ end
34
+
@@ -0,0 +1,62 @@
1
+ module Fabychy
2
+ class Bot
3
+ API_ENDPOINT = 'https://graph.facebook.com/v2.6'
4
+
5
+ attr_reader :me
6
+
7
+ def initialize(token)
8
+ @access_token = token
9
+ @offset = 0
10
+ @timeout = 60
11
+ @fail_silently = false
12
+ @connection = HTTPClient.new
13
+ end
14
+
15
+ def send_message(message)
16
+ api_post("me/messages?access_token=#{@access_token}", Fabychy::Sanitizer.sanitize(message))
17
+ end
18
+
19
+ def get_user(user_id)
20
+ response = api_get("#{user_id}?fields=first_name,last_name,profile_pic&access_token=#{@access_token}")
21
+ Fabychy::DataTypes::User.new(response.result)
22
+ end
23
+
24
+ private
25
+
26
+
27
+ def api_get(action)
28
+ api_uri = "#{action}"
29
+ begin
30
+ response = @connection.get(
31
+ "#{API_ENDPOINT}/#{api_uri}",
32
+ nil
33
+ )
34
+
35
+ ApiResponse.new(response,@fail_silently)
36
+ rescue HTTPClient::ReceiveTimeoutError => e
37
+ if !@fail_silently
38
+ fail Fabychy::Errors::TimeoutError, e.to_s
39
+ end
40
+ end
41
+ end
42
+
43
+ def api_post(action, params)
44
+ api_uri = "#{action}"
45
+
46
+ begin
47
+ response = @connection.post(
48
+ "#{API_ENDPOINT}/#{api_uri}",
49
+ MultiJson.dump(params),
50
+ 'Content-Type' => 'application/json'
51
+ )
52
+
53
+ ApiResponse.new(response,@fail_silently)
54
+ rescue HTTPClient::ReceiveTimeoutError => e
55
+ if !@fail_silently
56
+ fail Fabychy::Errors::TimeoutError, e.to_s
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Address < Fabychy::DataTypes::Base
4
+ attribute :street_1, String
5
+ attribute :street_2, String
6
+ attribute :city, String
7
+ attribute :postal_code, String
8
+ attribute :state, String
9
+ attribute :country, String
10
+
11
+ def initialize *params
12
+ super(*params)
13
+ end
14
+
15
+ def validations
16
+ {
17
+ street_1: { required: true, class: [String] },
18
+ street_2: { required: false, drop_empty: true, class: [String] },
19
+ city: { required: true, class: [String] },
20
+ postal_code: { required: true, class: [String] },
21
+ state: { required: true, class: [String] },
22
+ country: { required: true, class: [String] },
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,20 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Adjustment < Fabychy::DataTypes::Base
4
+ attribute :name, String
5
+ attribute :amount, Integer
6
+
7
+ def initialize *params
8
+ super(*params)
9
+ end
10
+
11
+ def validations
12
+ {
13
+ name: { required: false, class: [String] },
14
+ amount: { required: false, class: [Fixnum] },
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,14 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Attachment < Fabychy::DataTypes::Base
4
+ attribute :type, String
5
+ attribute :payload, Payload
6
+
7
+ def validations
8
+ {
9
+ type: { required: true, class: [String] } ,
10
+ }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Base
4
+ include Virtus.model
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Button < Fabychy::DataTypes::Base
4
+ attribute :type, String
5
+ attribute :title, String
6
+ attribute :url, String
7
+ attribute :payload, String
8
+
9
+ def initialize *params
10
+ super(*params)
11
+ end
12
+
13
+ def validations
14
+ {
15
+ type: { required: true, class: [String], in: ["web_url", "postback"] },
16
+ title: { required: true, class: [String] },
17
+ url: { required: false, drop_empty:true, class: [String], exclusive: true },
18
+ payload: { required: false, drop_empty: true, class: [String], exclusive: true },
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,22 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class ButtonTemplatePayload < Fabychy::DataTypes::Payload
4
+ attribute :text, String
5
+ attribute :buttons, Array[Button]
6
+ def initialize *params
7
+ super(*params)
8
+ @template_type = 'button'
9
+ end
10
+
11
+ def validations
12
+ super.merge(
13
+ {
14
+ text: {required: false, drop_empty: true, class: [String] },
15
+ buttons: {required: true, class: [Array], inner_class: [Button] }
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,22 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Element < Fabychy::DataTypes::Base
4
+ attribute :title, String
5
+ attribute :subtitle, String
6
+ attribute :image_url, String
7
+
8
+ def initialize *params
9
+ super(*params)
10
+ end
11
+
12
+ def validations
13
+ {
14
+ title: { required: true, class: [String] },
15
+ subtitle: { required: false, class: [String] },
16
+ image_url: { required: false, drop_empty: true, class: [String] },
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,22 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class GenericElement < Fabychy::DataTypes::Element
4
+ attribute :item_url, String
5
+ attribute :buttons, Array[Fabychy::DataTypes::Button], :default => nil
6
+
7
+ def initialize *params
8
+ super(*params)
9
+ end
10
+
11
+ def validations
12
+ super.merge(
13
+ {
14
+ item_url: { required: false, drop_empty: true, class: [String] },
15
+ buttons: { required: false, drop_empty: true, class: [Array], inner_class: [Fabychy::DataTypes::Button] },
16
+ }
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,20 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class GenericTemplatePayload < Fabychy::DataTypes::Payload
4
+ attribute :elements, Array[Element]
5
+ def initialize *params
6
+ super(*params)
7
+ @template_type = 'generic'
8
+ end
9
+
10
+ def validations
11
+ super.merge(
12
+ {
13
+ elements: {required: true, class: [Array], inner_class: [GenericElement] }
14
+ }
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,21 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class ImageAttachment < Fabychy::DataTypes::Attachment
4
+ attribute :payload, ImagePayload
5
+
6
+ def initialize *params
7
+ super(*params)
8
+ @type = 'image'
9
+ end
10
+
11
+ def validations
12
+ super.merge(
13
+ {
14
+ payload: {required: true, class: [ImagePayload] }
15
+ }
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,14 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class ImagePayload < Fabychy::DataTypes::Payload
4
+ attribute :url, String
5
+
6
+ def validations
7
+ {
8
+ url: {required: true, class: [String]}
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,16 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class MessageBody < Fabychy::DataTypes::Base
4
+ attribute :text, String
5
+ attribute :attachment, Attachment
6
+
7
+ def validations
8
+ {
9
+ text: {required: true, class: [String], drop_empty: true, exclusive: true },
10
+ attachment: {required: true, class: [TemplateAttachment, ImageAttachment], drop_empty: true, exclusive: true }
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,14 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Payload < Fabychy::DataTypes::Base
4
+ attribute :template_type, String
5
+
6
+ def validations
7
+ {
8
+ template_type: {required: true, class: [String]}
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,21 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class ReceiptElement < Fabychy::DataTypes::Element
4
+ attribute :quantity, Integer
5
+ attribute :price, Integer
6
+ attribute :currency, String
7
+
8
+ def validations
9
+ super.merge (
10
+ {
11
+ quantity: {required: false, drop_empty: true, class: [Fixnum] },
12
+ price: {required: false, drop_empty: true, class: [Fixnum] },
13
+ currency: {required: false, drop_empty: true, class: [String] }
14
+ }
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,40 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class ReceiptTemplatePayload < Fabychy::DataTypes::Payload
4
+ attribute :recipient_name, String
5
+ attribute :order_number, String
6
+ attribute :currency, String
7
+ attribute :payment_method, String
8
+ attribute :timestamp, String
9
+ attribute :order_url, String
10
+ attribute :elements, String
11
+ attribute :address, Address
12
+ attribute :summary, Summary
13
+ attribute :adjustments, Adjustment
14
+
15
+ def initialize *params
16
+ super(*params)
17
+ @template_type = 'receipt'
18
+ end
19
+
20
+ def validations
21
+ super.merge(
22
+ {
23
+ recipient_name: {required: true, class: [String] },
24
+ order_number: {required: true, class: [String] },
25
+ currency: {required: true, class: [String] },
26
+ payment_method: {required: true, class: [String] },
27
+ timestamp: {required: false, drop_empty: true, class: [String] },
28
+ order_url: {required: true, class: [String] },
29
+ elements: {required: true, class: [Array], inner_class: [ReceiptElement] },
30
+ address: {required: false, drop_empty: true, class: [Address] },
31
+ summary: {required: true, class: [Summary] },
32
+ adjustments: {required: false, class: [Adjustment] }
33
+ }
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,16 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Recipient < Fabychy::DataTypes::Base
4
+ attribute :id, String
5
+ attribute :phone_number, String
6
+
7
+ def validations
8
+ {
9
+ id: {required: false, drop_empty: true, class: [String] },
10
+ phone_number: { required: false, drop_empty: true, class: [String] }
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,20 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class Summary < Fabychy::DataTypes::Base
4
+ attribute :subtotal, Integer
5
+ attribute :shipping_cost, Integer
6
+ attribute :total_tax, Integer
7
+ attribute :total_cost, Integer
8
+
9
+ def validations
10
+ {
11
+ subtotal: { required: false, class: [Fixnum] },
12
+ shipping_cost: { required: false, class: [Fixnum] },
13
+ total_tax: { required: false, class: [Fixnum] },
14
+ total_cost: { required: true, class: [Fixnum] },
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,21 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class TemplateAttachment < Fabychy::DataTypes::Attachment
4
+ attribute :payload, Payload
5
+
6
+ def initialize *params
7
+ super(*params)
8
+ @type = 'template'
9
+ end
10
+
11
+ def validations
12
+ super.merge(
13
+ {
14
+ payload: {required: true, class: [GenericTemplatePayload, ReceiptTemplatePayload, ButtonTemplatePayload] }
15
+ }
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,10 @@
1
+ module Fabychy
2
+ module DataTypes
3
+ class User < Fabychy::DataTypes::Base
4
+ attribute :first_name, String
5
+ attribute :last_name, String
6
+ attribute :profile_pic, String
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,14 @@
1
+ module Fabychy
2
+ class Notification
3
+ REGULAR = "REGULAR"
4
+ SILENT_PUSH = "SILENT_PUSH"
5
+ NO_PUSH = "NO_PUSH"
6
+ end
7
+
8
+ class Message < Fabychy::DataTypes::Base
9
+ attribute :recipient, DataTypes::Recipient
10
+ attribute :message, DataTypes::MessageBody
11
+ attribute :notification_type, String
12
+ end
13
+ end
14
+
@@ -0,0 +1,69 @@
1
+ module Fabychy
2
+ class Sanitizer
3
+
4
+ def self.sanitize(object)
5
+ return object if object.class.name !~ /Fabychy::/
6
+ internal = sanitize_internal(object)
7
+ h = Hash.new
8
+ object.attributes.each do |k, att|
9
+ next unless internal.nil? || internal.key?(k)
10
+ if !att.is_a? Array
11
+ h[k]=sanitize(att)
12
+ else
13
+ h[k]=Array.new
14
+ att.each do |attr|
15
+ h[k] << sanitize(attr)
16
+ end
17
+ end
18
+ end
19
+ return h
20
+ end
21
+
22
+ def self.sanitize_internal(object)
23
+ return if !object.methods.include?(:validations)
24
+ # Delete params not accepted by the API
25
+ validated_param = object.to_hash.delete_if do |k, _v|
26
+ !object.validations.key?(k) || (object.validations[k][:drop_empty] && (_v.nil? || (_v.is_a?(Array) && _v.empty?)))
27
+ end
28
+
29
+ exclusives = object.validations.select{|k,v| v[:exclusive] }.keys
30
+ valid_exclusives = object.validations.select{|k,v| v[:exclusive] }.keys & validated_param.keys
31
+ if valid_exclusives.size > 1
32
+ fail Fabychy::Errors::ExclusivityError.new(exclusive_elements)
33
+ end
34
+ ignored_exclusive = exclusives - valid_exclusives
35
+ # Check all required params by the action are present
36
+ object.validations.each do |key, _value|
37
+ next if ignored_exclusive.include?(key)
38
+ if _value[:required] && (!validated_param.key?(key) || validated_param[key].nil?)
39
+ fail Fabychy::Errors::MissingParamsError.new(key, object.class.name)
40
+ end
41
+
42
+ # Check param types
43
+ unless _value[:class].include?(validated_param[key].class) || (_value[:drop_empty] && validated_param[key].nil?)
44
+ fail Fabychy::Errors::InvalidParamTypeError.new(key, validated_param[key].class, _value[:class])
45
+ end
46
+
47
+ if _value[:class] && _value[:class].include?(Array)
48
+ if validated_param[key].empty?
49
+ fail Fabychy::Errors::InvalidParamValueError.new(key, validated_param[key], ["should not be empty"])
50
+ end
51
+ if _value[:inner_class]
52
+ validated_param[key].each do |v|
53
+ unless _value[:inner_class].include?(v.class)
54
+ fail Fabychy::Errors::InvalidParamTypeError.new(key, validated_param[key].class, _value[:inner_class])
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ unless _value[:in].nil? || _value[:in].include?(validated_param[key])
61
+ fail Fabychy::Errors::InvalidParamValueError.new(key, validated_param[key], _value[:in])
62
+ end
63
+ validated_param[key] = validated_param[key].to_s if _value[:class] == Fixnum
64
+ end
65
+
66
+ return validated_param
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,74 @@
1
+
2
+ require 'httpclient'
3
+ require 'virtus'
4
+ require 'multi_json'
5
+
6
+ require 'fabychy/version'
7
+ require 'fabychy/data_types/base'
8
+
9
+ require 'fabychy/data_types/payload'
10
+ require 'fabychy/data_types/element'
11
+ require 'fabychy/data_types/button'
12
+
13
+ require 'fabychy/data_types/receipt_element'
14
+ require 'fabychy/data_types/generic_element'
15
+
16
+ require 'fabychy/data_types/address'
17
+ require 'fabychy/data_types/adjustment'
18
+ require 'fabychy/data_types/summary'
19
+ require 'fabychy/data_types/attachment'
20
+
21
+ require 'fabychy/data_types/generic_template_payload'
22
+ require 'fabychy/data_types/button_template_payload'
23
+ require 'fabychy/data_types/receipt_template_payload'
24
+ require 'fabychy/data_types/image_payload'
25
+
26
+ require 'fabychy/data_types/image_attachment'
27
+ require 'fabychy/data_types/template_attachment'
28
+
29
+ require 'fabychy/data_types/recipient'
30
+ require 'fabychy/data_types/message_body'
31
+ require 'fabychy/data_types/user'
32
+
33
+ require 'fabychy/message'
34
+ require 'fabychy/bot'
35
+ require 'fabychy/api_response'
36
+
37
+ module Fabychy
38
+ module Errors
39
+ # Error returned when a required param is missing
40
+ class MissingParamsError < StandardError
41
+ def initialize(parameter, action)
42
+ super("Missing parameter `#{parameter}` for `#{action}`")
43
+ end
44
+ end
45
+
46
+ # Error returned when a param type is invalid
47
+ class InvalidParamTypeError < StandardError
48
+ def initialize(parameter, current_type, allowed_types)
49
+ super("Invalid parameter type: `#{parameter}`: `#{current_type}`. Allowed types: #{allowed_types.each { |type| type.class.to_s }.join(',')}.")
50
+ end
51
+ end
52
+
53
+ # Error returned when something goes bad with your request to the fabychy API
54
+ class BadRequestError < StandardError
55
+ def initialize(error_code, message)
56
+ super("Bad request. Error code: `#{error_code}` - Message: `#{message}`")
57
+ end
58
+ end
59
+
60
+ # Error returned when fabychy API Service is unavailable
61
+ class ServiceUnavailableError < StandardError
62
+ def initialize(status_code)
63
+ super("fabychy API Service unavailable (HTTP error code #{status_code})")
64
+ end
65
+ end
66
+
67
+ # Error returned when HTTPClient raise a timeout (?)
68
+ class TimeoutError < StandardError
69
+ def initialize(message)
70
+ super("Timeout reached. Message: #{message}")
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ module Fabychy
2
+ VERSION = '0.0.1'
3
+ end
4
+
data/lib/fabychy.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'httpclient'
2
+ require 'virtus'
3
+ require 'multi_json'
4
+
5
+ require 'fabychy/version'
6
+ require 'fabychy/data_types/base'
7
+
8
+ require 'fabychy/data_types/payload'
9
+ require 'fabychy/data_types/element'
10
+ require 'fabychy/data_types/button'
11
+
12
+ require 'fabychy/data_types/receipt_element'
13
+ require 'fabychy/data_types/generic_element'
14
+
15
+ require 'fabychy/data_types/address'
16
+ require 'fabychy/data_types/adjustment'
17
+ require 'fabychy/data_types/summary'
18
+ require 'fabychy/data_types/attachment'
19
+
20
+ require 'fabychy/data_types/generic_template_payload'
21
+ require 'fabychy/data_types/button_template_payload'
22
+ require 'fabychy/data_types/receipt_template_payload'
23
+ require 'fabychy/data_types/image_payload'
24
+
25
+ require 'fabychy/data_types/image_attachment'
26
+ require 'fabychy/data_types/template_attachment'
27
+
28
+ require 'fabychy/data_types/recipient'
29
+ require 'fabychy/data_types/message_body'
30
+
31
+ require 'fabychy/sanitizer'
32
+ require 'fabychy/message'
33
+ require 'fabychy/user'
34
+ require 'fabychy/bot'
35
+ require 'fabychy/api_response'
36
+
37
+ module Fabychy
38
+ module Errors
39
+ # Error returned when a required param is missing
40
+ class MissingParamsError < StandardError
41
+ def initialize(parameter, action)
42
+ super("Missing parameter `#{parameter}` for `#{action}`")
43
+ end
44
+ end
45
+
46
+ class ExclusivityError < StandardError
47
+ def initialize(param_list)
48
+ super("Only one of the following is allowed `#{param_list}`")
49
+ end
50
+ end
51
+
52
+ # Error returned when a param type is invalid
53
+ class InvalidParamTypeError < StandardError
54
+ def initialize(parameter, current_type, allowed_types)
55
+ super("Invalid parameter type: `#{parameter}`: `#{current_type}`. Allowed types: #{allowed_types.each { |type| type.class.to_s }.join(',')}.")
56
+ end
57
+ end
58
+
59
+ # Error returned when a param type is invalid
60
+ class InvalidParamValueError < StandardError
61
+ def initialize(parameter, current_value, allowed_values)
62
+ super("Invalid parameter value: `#{parameter}`: `#{current_value}`. Allowed values: #{allowed_values.each { |type| type.class.to_s }.join(',')}.")
63
+ end
64
+ end
65
+
66
+ # Error returned when something goes bad with your request to the fabychy API
67
+ class BadRequestError < StandardError
68
+ def initialize(error_code, message)
69
+ super("Bad request. Error code: `#{error_code}` - Message: `#{message}`")
70
+ end
71
+ end
72
+
73
+ # Error returned when fabychy API Service is unavailable
74
+ class ServiceUnavailableError < StandardError
75
+ def initialize(status_code)
76
+ super("fabychy API Service unavailable (HTTP error code #{status_code})")
77
+ end
78
+ end
79
+
80
+ # Error returned when HTTPClient raise a timeout (?)
81
+ class TimeoutError < StandardError
82
+ def initialize(message)
83
+ super("Timeout reached. Message: #{message}")
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fabychy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nima Kaviani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.1'
83
+ description: Ruby client for Facebook Bot API
84
+ email:
85
+ - nima@robochy.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - fabychy.gemspec
95
+ - lib/fabychy.rb
96
+ - lib/fabychy/api_response.rb
97
+ - lib/fabychy/bot.rb
98
+ - lib/fabychy/data_types/address.rb
99
+ - lib/fabychy/data_types/adjustment.rb
100
+ - lib/fabychy/data_types/attachment.rb
101
+ - lib/fabychy/data_types/base.rb
102
+ - lib/fabychy/data_types/button.rb
103
+ - lib/fabychy/data_types/button_template_payload.rb
104
+ - lib/fabychy/data_types/element.rb
105
+ - lib/fabychy/data_types/generic_element.rb
106
+ - lib/fabychy/data_types/generic_template_payload.rb
107
+ - lib/fabychy/data_types/image_attachment.rb
108
+ - lib/fabychy/data_types/image_payload.rb
109
+ - lib/fabychy/data_types/message_body.rb
110
+ - lib/fabychy/data_types/payload.rb
111
+ - lib/fabychy/data_types/receipt_element.rb
112
+ - lib/fabychy/data_types/receipt_template_payload.rb
113
+ - lib/fabychy/data_types/recipient.rb
114
+ - lib/fabychy/data_types/summary.rb
115
+ - lib/fabychy/data_types/template_attachment.rb
116
+ - lib/fabychy/data_types/user.rb
117
+ - lib/fabychy/message.rb
118
+ - lib/fabychy/sanitizer.rb
119
+ - lib/fabychy/user.rb
120
+ - lib/fabychy/version.rb
121
+ homepage: https://github.com/nkaviani/fabychy
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Ruby client for Facebook Bot API
145
+ test_files: []