Sha256: ba48703cb0c1689fb7f0b0b451f9e253875e3e71fe13cd24d4038346c9548849

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require "impas-client/version"
require 'faraday'

module Impas
  class Client
    attr_accessor :api_url, :op_key

    def initialize(args)
      @api_url  = (args[:api_url].nil?) ? API_URL : args[:api_url]
      @op_key   = args[:op_key]

      @@conn = Faraday.new(:url => @api_url) 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

    def add_group(group_name)
      entry_point = "/api/group/#{@op_key}"

      @@conn.post do |req|
        req.url entry_point
        req.headers['Content-Type'] = 'application/json'
        req.body = "{\"name\":\"#{group_name}\"}"
      end
    end

    def groups
      entry_point = "/api/group/#{@op_key}"
      @@conn.get entry_point
    end

    def add_url(grp_key, url)
      entry_point = "/api/registration/#{grp_key}"

      @@conn.post do |req|
        req.url entry_point
        req.headers['Content-Type'] = 'application/json'
        req.body = "{\"url\":\"#{url}\"}"
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
impas-client-0.0.2 lib/impas-client.rb