lib/impas-client.rb in impas-client-0.0.1 vs lib/impas-client.rb in impas-client-0.0.2
- old
+ new
@@ -1,7 +1,45 @@
require "impas-client/version"
+require 'faraday'
module Impas
- module Client
- # Your code goes here...
+ 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