Module: Eventick

Defined in:
lib/eventick.rb,
lib/eventick/auth.rb,
lib/eventick/base.rb,
lib/eventick/event.rb,
lib/eventick/checkin.rb,
lib/eventick/version.rb,
lib/eventick/attendee.rb

Defined Under Namespace

Classes: Attendee, Auth, Base, Checkin, Event, Ticket

Constant Summary collapse

BASE_URL =
'www.eventick.com.br'
BASE_PATH =
'/api/v1/'
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.api_path(resource) ⇒ Object



57
58
59
# File 'lib/eventick.rb', line 57

def self.api_path(resource)
  BASE_PATH + resource
end

.authObject



65
66
67
# File 'lib/eventick.rb', line 65

def self.auth
  @auth
end

.auth_tokenObject



61
62
63
# File 'lib/eventick.rb', line 61

def self.auth_token
  @auth.token if @auth
end

.config(&block) ⇒ Object



17
18
19
# File 'lib/eventick.rb', line 17

def self.config(&block)
  @auth = Eventick::Auth.new &block
end

.get(resource, params = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/eventick.rb', line 21

def self.get(resource, params={})
  path = api_path resource
  path = with_params path, params
  method = Net::HTTP::Get.new(path)

  request(method)
end

.put(resource, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/eventick.rb', line 29

def self.put(resource, params={})
  path = api_path resource
  method = Net::HTTP::Put.new(path)
  method.set_form_data(params)
  method.content_type = 'application/json' if params.is_a? String

  request(method, params)
end

.request(method, params = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/eventick.rb', line 38

def self.request(method, params={})
  uri = URI("https://#{ BASE_URL }")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  if auth && auth.authenticated?
      method.basic_auth auth_token, ""
  end

  response = http.start do |http|
      http.request method
  end

  return { } unless response.is_a? Net::HTTPSuccess
  # return response.body unless block_given?
  # yield JSON.parse(response.body)
   JSON.parse(response.body)  unless response.body.nil?
end