class PushWoosher::Base

Constants

BASE_HOST
BASE_PATH
PROTOCOL

Public Instance Methods

config() click to toggle source
# File lib/push_woosher/base.rb, line 32
def config
  {
    application: PushWoosher.configuration.application_code,
    auth: PushWoosher.configuration.api_token
  }
end
connection() click to toggle source
# File lib/push_woosher/base.rb, line 9
def connection
  @connection = Faraday.new(url: "#{PROTOCOL}://#{BASE_HOST}") do |faraday|
    faraday.request :url_encoded             # form-encode POST params
    faraday.response :logger                  # log requests to STDOUT
    faraday.adapter Faraday.default_adapter  # make requests with Net::HTTP
  end
end
post_action(opts = {}) click to toggle source
# File lib/push_woosher/base.rb, line 17
def post_action(opts = {})
  response = connection.post do |req|
    req.url "#{BASE_PATH}/#{opts[:path]}"
    req.headers['Content-Type'] = 'application/json'
    req.body = { request: opts[:request_hash].merge(config) }.to_json
  end

  case response.status
  when 200
    true
  else
    { status: response.status, message: response.body }
  end
end