Class: Korboard::Client
- Inherits:
-
Object
- Object
- Korboard::Client
- Defined in:
- lib/korboard/client.rb
Instance Method Summary collapse
-
#initialize(params) ⇒ Client
constructor
A new instance of Client.
- #print_response(resp, data) ⇒ Object
- #record(metric, iteration_number, identifier, options = { }) ⇒ Object
- #record_invite(identifier, options = { }) ⇒ Object
- #record_paid(identifier, options = { }) ⇒ Object
-
#record_signup(identifier, session_id, options = { }, parent_user_id = nil) ⇒ Object
can do this for the rest too parent_user_id => user_id_of_invitor can be passed in the options.
- #record_value(identifier, options = { }) ⇒ Object
- #record_visit(identifier, options = { }) ⇒ Object
Constructor Details
#initialize(params) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/korboard/client.rb', line 8 def initialize params @token = params[:api_secret] @iteration_number = params[:iteration] @http = Net::HTTP.new('api.korboard.com') @headers = { 'Content-Type' => 'application/json' } end |
Instance Method Details
#print_response(resp, data) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/korboard/client.rb', line 66 def print_response(resp,data) puts 'Code = ' + resp.code puts 'Message = ' + resp. resp.each {|key, val| puts key + ' = ' + val} puts data end |
#record(metric, iteration_number, identifier, options = { }) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/korboard/client.rb', line 47 def record metric ,iteration_number, identifier, ={ } data = { :signup => { :identifier => identifier}, :iteration => { :number => iteration_number } } data.merge!() path = "/v1.1/#{metric.to_s.pluralize}?token=#{@token}" #wrap in a timeout so we don't slow shit down Timeout::timeout(1){ resp, data = @http.post(path, data.to_json, @headers) print_response(resp,data) unless resp.code.to_i == 201 return resp.code.to_i == 201 } return false rescue => e puts e. end |
#record_invite(identifier, options = { }) ⇒ Object
32 33 34 35 |
# File 'lib/korboard/client.rb', line 32 def record_invite identifier,={ } .merge! :user_profile => { :session_id => identifier } record :invite,@iteration_number,identifier, end |
#record_paid(identifier, options = { }) ⇒ Object
42 43 44 45 |
# File 'lib/korboard/client.rb', line 42 def record_paid identifier,={ } .merge! :user_profile => { :session_id => identifier } record :paid,@iteration_number,identifier, end |
#record_signup(identifier, session_id, options = { }, parent_user_id = nil) ⇒ Object
can do this for the rest too parent_user_id => user_id_of_invitor can be passed in the options
21 22 23 24 25 |
# File 'lib/korboard/client.rb', line 21 def record_signup identifier,session_id,={ },parent_user_id=nil .merge! :signup => { :parent_user_id => parent_user_id} if parent_user_id .merge! :user_profile => { :session_id => session_id , :user_id => identifier} record :signup,@iteration_number,identifier, end |
#record_value(identifier, options = { }) ⇒ Object
37 38 39 40 |
# File 'lib/korboard/client.rb', line 37 def record_value identifier,={ } .merge! :user_profile => { :session_id => identifier } record :value,@iteration_number,identifier, end |
#record_visit(identifier, options = { }) ⇒ Object
27 28 29 30 |
# File 'lib/korboard/client.rb', line 27 def record_visit identifier,={ } .merge! :user_profile => { :session_id => identifier } record :visit,@iteration_number,identifier, end |