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,
lib/eventick/exceptions.rb,
lib/eventick/params_parser.rb

Defined Under Namespace

Classes: Attendee, Auth, Base, Checkin, Event, EventickError, InvalidResource, ParamsParser, Ticket, UnmatchableParams

Constant Summary collapse

BASE_URL =
'www.eventick.com.br'
BASE_PATH =
'/api/v1/'
MAJOR =
0
MINOR =
1
PATCH =
1
VERSION =
"#{MAJOR}.#{MINOR}.#{PATCH}"

Class Method Summary collapse

Class Method Details

.api_path(resource) ⇒ Object



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

def self.api_path(resource)
  BASE_PATH + resource
end

.authObject



68
69
70
# File 'lib/eventick.rb', line 68

def self.auth
  @auth
end

.auth_tokenObject



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

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

.config(&block) ⇒ Object



20
21
22
# File 'lib/eventick.rb', line 20

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

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



24
25
26
27
28
29
30
# File 'lib/eventick.rb', line 24

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



32
33
34
35
36
37
38
39
# File 'lib/eventick.rb', line 32

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



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

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