Sha256: fccb4e68b1a61a7efede3d0287549dd80945e6c52b47b2bbfe17c40609fb78dd

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'faraday'

module FirstGiving
  module Base
    DONATION_SANDBOX_ENDPOINT    = 'http://usapisandbox.fgdev.net'
    DONATION_PRODUCTION_ENDPOINT = 'https://api.firstgiving.com'
    SEARCH_ENDPOINT = 'http://graphapi.firstgiving.com'

    def headers_json
      {
        'User-Agent'        => 'FirstGiving Ruby SDK',
        'Content-Type'      => 'application/json'
      }
    end

    def headers_security
      {
        'JG_APPLICATIONKEY' => "#{FirstGiving.configuration.application_key}",
        'JG_SECURITYTOKEN'  => "#{FirstGiving.configuration.security_token}"
      }
    end

    def post_call(api_endpoint, action, params, headers)
      conn = Faraday.new(url: api_endpoint) do |faraday|
        faraday.request  :url_encoded
        faraday.adapter  Faraday.default_adapter
      end

      conn.post do |req|
        req.url action
        req.params = params
        req.headers = headers
      end
    end

    def get_call(api_endpoint, action, params, headers)
      conn = Faraday.new(url: api_endpoint) do |faraday|
        faraday.request  :url_encoded             # form-encode POST params
        faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
      end

      conn.get do |req|
        req.url action
        req.params = params
        req.headers = headers
      end
    end

    def logging(msg)
      puts "[FG-LOG] #{msg}" if FirstGiving.configuration.options[:verbose]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
firstgiving-1.0.1 lib/firstgiving/base.rb