Class: Flutterwave
- Inherits:
-
Object
- Object
- Flutterwave
- Defined in:
- lib/flutterwave_sdk.rb
Instance Attribute Summary collapse
-
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
-
#production ⇒ Object
Returns the value of attribute production.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #base_url ⇒ Object
-
#flutterwave_tracking ⇒ Object
tracking activities.
-
#initialize(public_key = nil, secret_key = nil, encryption_key = nil, production = false) ⇒ Flutterwave
constructor
method to initialize flutterwave object.
Constructor Details
#initialize(public_key = nil, secret_key = nil, encryption_key = nil, production = false) ⇒ Flutterwave
method to initialize flutterwave object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/flutterwave_sdk.rb', line 33 def initialize(public_key=nil, secret_key=nil, encryption_key=nil, production=false) @public_key = public_key @secret_key = secret_key @production = production @encryption_key = encryption_key flutterwave_sandbox_url = BASE_ENDPOINTS::FLUTTERWAVE_SANDBOX_URL flutterwave_live_url = BASE_ENDPOINTS::FLUTTERWAVE_LIVE_URL # set rave url to sandbox or live if we are in production or development if production == false @url = flutterwave_sandbox_url else @url = flutterwave_live_url end def base_url return url end # check if we set our public , secret and encryption keys to the environment variable if (public_key.nil?) @public_key = ENV['FLUTTERWAVE_PUBLIC_KEY'] else @public_key = public_key end if (secret_key.nil?) @secret_key = ENV['FLUTTERWAVE_SECRET_KEY'] else @secret_key = secret_key end if (encryption_key.nil?) @encryption_key = ENV['FLUTTERWAVE_ENCRYPTION_KEY'] else @encryption_key = encryption_key end warn "Warning: To ensure your rave account api keys are safe, It is best to always set your keys in the environment variable" # raise this error if no public key is passed unless !@public_key.nil? raise FlutterwaveBadKeyError, "No public key supplied and couldn't find any in environment variables. Make sure to set public key as an environment variable FLUTTERWAVE_PUBLIC_KEY" end # raise this error if invalid public key is passed unless @public_key[0..7] == 'FLWPUBK-' || @public_key[0..11] == 'FLWPUBK_TEST' raise FlutterwaveBadKeyError, "Invalid public key #{@public_key}" end # raise this error if no secret key is passed unless !@secret_key.nil? raise FlutterwaveBadKeyError, "No secret key supplied and couldn't find any in environment variables. Make sure to set secret key as an environment variable FLUTTERWAVE_SECRET_KEY" end # raise this error if invalid secret key is passed unless @secret_key[0..7] == 'FLWSECK-' || @secret_key[0..11] == 'FLWSECK_TEST' raise FlutterwaveBadKeyError, "Invalid secret key #{@secret_key}" end # raise this error if no encryption key is passed unless !@encryption_key.nil? raise FlutterwaveBadKeyError, "No encryption key supplied and couldn't find any in environment variables. Make sure to set encryption key as an environment variable FLUTTERWAVE_ENCRYPTION_KEY" end end |
Instance Attribute Details
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
30 31 32 |
# File 'lib/flutterwave_sdk.rb', line 30 def encryption_key @encryption_key end |
#production ⇒ Object
Returns the value of attribute production.
30 31 32 |
# File 'lib/flutterwave_sdk.rb', line 30 def production @production end |
#public_key ⇒ Object
Returns the value of attribute public_key.
30 31 32 |
# File 'lib/flutterwave_sdk.rb', line 30 def public_key @public_key end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
30 31 32 |
# File 'lib/flutterwave_sdk.rb', line 30 def secret_key @secret_key end |
#url ⇒ Object
Returns the value of attribute url.
30 31 32 |
# File 'lib/flutterwave_sdk.rb', line 30 def url @url end |
Instance Method Details
#base_url ⇒ Object
48 49 50 |
# File 'lib/flutterwave_sdk.rb', line 48 def base_url return url end |
#flutterwave_tracking ⇒ Object
tracking activities
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/flutterwave_sdk.rb', line 97 def flutterwave_tracking endpoint = "https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/staging/sendevent" public_key = @public_key payload = { "PBFPubKey" => public_key, "language" => "Ruby", "version" => "1.0", "title" => "test message", "message" => "test is done" } data = payload.to_json response = HTTParty.post(endpoint, { body: data, headers: { 'Content-Type' => 'application/json' } }) unless (response.code == 200 || response.code == 201) raise RaveServerError.new(response), "HTTP Code #{response.code}: #{response.body}" end return response end |