Sha256: d8c2068a5ee892418a8b646695d16986eec617510d6c21b4cc79730bdf487e5b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Sendicate
  
  class Request
    include HTTParty
    base_uri 'https://api.sendicate.net/v1'
    headers 'Accept' => 'application/json', 'Content-Type' => 'application/json', "Authorization" => "token #{Sendicate.api_token}"
    
    attr_accessor :response
    
    def self.get(path, options={}, &block)
      new(super)
    end
    
    def self.post(path, options={}, &block)
      new(super)
    end
    
    def self.patch(path, options={}, &block)
      new(super)
    end
    
    def self.put(path, options={}, &block)
      new(super)
    end
    
    def self.delete(path, options={}, &block)
      new(super)
    end
    
    def initialize(response)
      @response = response
      unless success?
        case response.code
        when 400
          raise Sendicate::BadRequest
        when 401
          raise Sendicate::Unauthorized
        when 404
          raise Sendicate::ResourceNotFound
        end
      end
    end
    
    def parsed_response
      response.parsed_response
    end
    
    def success?
      [200, 201].include?(response.code)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sendicate-0.1.0 lib/sendicate/request.rb