welcu 0.0.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -3
- data/Gemfile.lock +20 -0
- data/README +12 -0
- data/lib/welcu_api.rb +78 -0
- data/lib/welcu_api/attendee.rb +83 -0
- data/lib/welcu_api/company.rb +11 -0
- data/lib/welcu_api/event.rb +44 -0
- data/lib/welcu_api/ticket.rb +30 -0
- data/welcu.gemspec +15 -23
- metadata +58 -107
- data/.gitignore +0 -4
- data/README.rdoc +0 -3
- data/Rakefile +0 -2
- data/lib/welcu.rb +0 -41
- data/lib/welcu/api.rb +0 -35
- data/lib/welcu/base.rb +0 -29
- data/lib/welcu/client.rb +0 -13
- data/lib/welcu/client/canvas.rb +0 -45
- data/lib/welcu/client/event.rb +0 -32
- data/lib/welcu/client/passes.rb +0 -48
- data/lib/welcu/client/registries.rb +0 -65
- data/lib/welcu/error.rb +0 -3
- data/lib/welcu/railtie.rb +0 -8
- data/lib/welcu/version.rb +0 -3
- data/spec/TODO +0 -1
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
welcu (0.1.4)
|
5
|
+
multi_json
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
mime-types (1.23)
|
12
|
+
multi_json (1.7.4)
|
13
|
+
rest-client (1.6.7)
|
14
|
+
mime-types (>= 1.16)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
welcu!
|
data/README
ADDED
data/lib/welcu_api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "rest_client"
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
require "welcu_api/event"
|
5
|
+
require "welcu_api/company"
|
6
|
+
require "welcu_api/ticket"
|
7
|
+
require "welcu_api/attendee"
|
8
|
+
|
9
|
+
module WelcuApi
|
10
|
+
@api_base = "http://api.welcu.com/v1"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :api_base, :api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.api_url(url='')
|
17
|
+
@api_base + url + '.json'
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.request(method, url, api_key, params={}, headers={})
|
21
|
+
api_key ||= @api_key
|
22
|
+
|
23
|
+
url = api_url(url)
|
24
|
+
|
25
|
+
case method.to_s.downcase.to_sym
|
26
|
+
when :get, :head, :delete
|
27
|
+
# Make params into GET parameters
|
28
|
+
url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
|
29
|
+
payload = nil
|
30
|
+
else
|
31
|
+
payload = uri_encode(params)
|
32
|
+
end
|
33
|
+
|
34
|
+
request_opts = { :headers => request_headers(api_key).update(headers),
|
35
|
+
:method => method, :open_timeout => 30,
|
36
|
+
:payload => payload, :url => url, :timeout => 80 }
|
37
|
+
|
38
|
+
response = execute_request(request_opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
def self.request_headers(api_key)
|
44
|
+
headers = {
|
45
|
+
:user_agent => "Welcu/v1 RubyBindings",
|
46
|
+
:authorization => "event #{api_key}",
|
47
|
+
:content_type => 'application/x-www-form-urlencoded'
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.uri_encode(params)
|
52
|
+
flatten_params(params).
|
53
|
+
map { |k,v| "#{k}=#{url_encode(v)}" }.join('&')
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.execute_request(opts)
|
57
|
+
RestClient::Request.execute(opts)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.url_encode(key)
|
61
|
+
URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.flatten_params(params, parent_key=nil)
|
65
|
+
result = []
|
66
|
+
params.each do |key, value|
|
67
|
+
calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
|
68
|
+
if value.is_a?(Hash)
|
69
|
+
result += flatten_params(value, calculated_key)
|
70
|
+
elsif value.is_a?(Array)
|
71
|
+
result += flatten_params_array(value, calculated_key)
|
72
|
+
else
|
73
|
+
result << [calculated_key, value]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
result
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module WelcuApi
|
2
|
+
class Attendee
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :first_name
|
5
|
+
attr_reader :last_name
|
6
|
+
attr_reader :title
|
7
|
+
attr_reader :email
|
8
|
+
attr_reader :phone
|
9
|
+
attr_reader :facebook_uid
|
10
|
+
attr_reader :reference_key
|
11
|
+
attr_reader :tickets
|
12
|
+
|
13
|
+
def initialize(attendee_json)
|
14
|
+
@id = attendee_json["id"].to_i
|
15
|
+
@first_name = attendee_json["first_name"]
|
16
|
+
@last_name = attendee_json["last_name"]
|
17
|
+
@organization = attendee_json["organization"]
|
18
|
+
@title = attendee_json["title"]
|
19
|
+
@email = attendee_json["email"]
|
20
|
+
@phone = attendee_json["phone"]
|
21
|
+
@facebook_uid = attendee_json["facebook_uid"]
|
22
|
+
@reference_key = attendee_json["reference_key"]
|
23
|
+
|
24
|
+
@tickets = []
|
25
|
+
attendee_json["tickets"].each do |ticket|
|
26
|
+
puts ticket.inspect
|
27
|
+
@tickets << WelcuApi::Ticket.new(ticket)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.all(options={})
|
32
|
+
case options[:state]
|
33
|
+
when :checked
|
34
|
+
url = WelcuApi::Attendee.checked_url
|
35
|
+
when :unchecked
|
36
|
+
url = WelcuApi::Attendee.unchecked_url
|
37
|
+
else
|
38
|
+
url = WelcuApi::Attendee.attendee_url
|
39
|
+
end
|
40
|
+
|
41
|
+
params = {}
|
42
|
+
params.update(ticket_id = options["ticket_id"]) unless options["ticket_id"].nil?
|
43
|
+
|
44
|
+
response = WelcuApi.request(:get, url, @api_key, {})
|
45
|
+
attendees_json = MultiJson.load(response)
|
46
|
+
|
47
|
+
attendees = []
|
48
|
+
attendees_json.each do |attendee_json|
|
49
|
+
attendees << WelcuApi::Attendee.new(attendee_json)
|
50
|
+
end
|
51
|
+
|
52
|
+
attendees
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.find_by_code(code)
|
56
|
+
response = WelcuApi.request(:get, WelcuApi::Attendee.attendee_by_code_url(code), @api_key, {})
|
57
|
+
attendee_json = MultiJson.load(response)
|
58
|
+
|
59
|
+
Attendee.new(attendee_json)
|
60
|
+
end
|
61
|
+
|
62
|
+
def full_name
|
63
|
+
"#{first_name} #{last_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def self.attendee_url
|
68
|
+
'/event/attendees'
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.checked_url
|
72
|
+
'/event/attendees/checked'
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.unchecked_url
|
76
|
+
'/event/attendees/unchecked'
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.attendee_by_code_url(code)
|
80
|
+
"/event/attendees/code/#{code}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module WelcuApi
|
2
|
+
class Event
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :starts_at
|
6
|
+
attr_reader :ends_at
|
7
|
+
attr_reader :locale
|
8
|
+
attr_reader :timezone
|
9
|
+
attr_reader :state
|
10
|
+
attr_reader :url
|
11
|
+
attr_reader :public
|
12
|
+
attr_reader :location
|
13
|
+
attr_reader :company
|
14
|
+
attr_reader :tickets
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
response = WelcuApi.request(:get, WelcuApi::Event.event_url, @api_key, {})
|
18
|
+
json_event = MultiJson.load(response)
|
19
|
+
|
20
|
+
@id = json_event["id"].to_i
|
21
|
+
@name = json_event["name"]
|
22
|
+
|
23
|
+
@starts_at = Time.new json_event["starts_at"]
|
24
|
+
@ends_at = Time.new json_event["ends_at"]
|
25
|
+
@locale = json_event["locale"].to_sym
|
26
|
+
@timezone = json_event["timezone"]
|
27
|
+
@state = json_event["state"].to_sym
|
28
|
+
@url = json_event["url"]
|
29
|
+
@public = json_event["public"] == "true"
|
30
|
+
@company = WelcuApi::Company.new(json_event["company"]["id"], json_event["company"]["name"])
|
31
|
+
@location = json_event["location"]
|
32
|
+
|
33
|
+
@tickets = []
|
34
|
+
json_event["tickets"].each do |ticket|
|
35
|
+
@tickets << WelcuApi::Ticket.new(ticket)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def self.event_url
|
41
|
+
'/event'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module WelcuApi
|
2
|
+
class Ticket
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :starts_at
|
6
|
+
attr_reader :ends_at
|
7
|
+
attr_reader :location
|
8
|
+
attr_reader :code
|
9
|
+
|
10
|
+
def initialize(ticket_json)
|
11
|
+
@id = (ticket_json["id"] || ticket_json["ticket_id"]).to_i
|
12
|
+
@name = ticket_json["name"]
|
13
|
+
@code = ticket_json["code"]
|
14
|
+
@starts_at = Time.new(ticket_json["starts_at"]) unless ticket_json["starts_at"].nil?
|
15
|
+
@ends_at = Time.new(ticket_json["ends_at"]) unless ticket_json["ends_at"].nil?
|
16
|
+
@location = ticket_json["location"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.check(code, checked_at=nil)
|
20
|
+
params = checked_at.nil? ? {} : uri_encode({ at: checked_at })
|
21
|
+
|
22
|
+
response = WelcuApi.request(:post, WelcuApi::Ticket.check_ticket_url(code), @api_key, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def self.check_ticket_url(code)
|
27
|
+
"/event/attendees/code/#{code}/check"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/welcu.gemspec
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
|
-
require "welcu/version"
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n") rescue
|
17
|
-
Dir['README.rdoc', 'Rakefile', 'lib/**/*', 'spec/**/*']
|
18
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") rescue Dir['spec/**/*']
|
19
|
-
s.executables = ( `git ls-files -- bin/*`.split("\n") rescue Dir['bin/*'] ).map{ |f| File.basename(f) }
|
6
|
+
s.name = 'welcu'
|
7
|
+
s.version = '0.1.5'
|
8
|
+
s.date = '2013-06-01'
|
9
|
+
s.summary = "Ruby wrapper for the Welcu API"
|
10
|
+
s.description = "Ruby wrapper for the Welcu API V1"
|
11
|
+
s.authors = ["Roberto Poo"]
|
12
|
+
s.email = 'xaro@poo.cl'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
20
14
|
s.require_paths = ["lib"]
|
21
|
-
|
22
|
-
|
23
|
-
s.add_runtime_dependency
|
24
|
-
|
25
|
-
|
26
|
-
s.add_development_dependency("bundler")
|
27
|
-
end
|
15
|
+
s.homepage = 'https://github.com/xaro/welcu_api'
|
16
|
+
|
17
|
+
s.add_runtime_dependency "rest-client"
|
18
|
+
s.add_runtime_dependency "multi_json"
|
19
|
+
end
|
metadata
CHANGED
@@ -1,134 +1,85 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: welcu
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
7
|
+
authors:
|
8
|
+
- Roberto Poo
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
name: oauth2
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
- 1
|
31
|
-
- 1
|
32
|
-
version: 0.1.1
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: json
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rake
|
50
|
-
prerelease: false
|
51
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
52
33
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
version: "0"
|
59
|
-
type: :development
|
60
|
-
version_requirements: *id003
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: bundler
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
63
39
|
prerelease: false
|
64
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
41
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
type: :development
|
73
|
-
version_requirements: *id004
|
74
|
-
description: A Gem for the Welcu API
|
75
|
-
email:
|
76
|
-
- seba@welcu.com
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby wrapper for the Welcu API V1
|
47
|
+
email: xaro@poo.cl
|
77
48
|
executables: []
|
78
|
-
|
79
49
|
extensions: []
|
80
|
-
|
81
50
|
extra_rdoc_files: []
|
82
|
-
|
83
|
-
files:
|
84
|
-
- .gitignore
|
51
|
+
files:
|
85
52
|
- Gemfile
|
86
|
-
-
|
87
|
-
-
|
88
|
-
- lib/
|
89
|
-
- lib/
|
90
|
-
- lib/
|
91
|
-
- lib/
|
92
|
-
- lib/
|
93
|
-
- lib/welcu/client/event.rb
|
94
|
-
- lib/welcu/client/passes.rb
|
95
|
-
- lib/welcu/client/registries.rb
|
96
|
-
- lib/welcu/error.rb
|
97
|
-
- lib/welcu/railtie.rb
|
98
|
-
- lib/welcu/version.rb
|
99
|
-
- spec/TODO
|
53
|
+
- Gemfile.lock
|
54
|
+
- README
|
55
|
+
- lib/welcu_api.rb
|
56
|
+
- lib/welcu_api/attendee.rb
|
57
|
+
- lib/welcu_api/company.rb
|
58
|
+
- lib/welcu_api/event.rb
|
59
|
+
- lib/welcu_api/ticket.rb
|
100
60
|
- welcu.gemspec
|
101
|
-
|
102
|
-
homepage: http://github.com/welcu/welcu.gem
|
61
|
+
homepage: https://github.com/xaro/welcu_api
|
103
62
|
licenses: []
|
104
|
-
|
105
63
|
post_install_message:
|
106
64
|
rdoc_options: []
|
107
|
-
|
108
|
-
require_paths:
|
65
|
+
require_paths:
|
109
66
|
- lib
|
110
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
68
|
none: false
|
112
|
-
requirements:
|
113
|
-
- -
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
|
116
|
-
|
117
|
-
version: "0"
|
118
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
74
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
|
124
|
-
- 0
|
125
|
-
version: "0"
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
126
79
|
requirements: []
|
127
|
-
|
128
80
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.25
|
130
82
|
signing_key:
|
131
83
|
specification_version: 3
|
132
|
-
summary:
|
133
|
-
test_files:
|
134
|
-
- spec/TODO
|
84
|
+
summary: Ruby wrapper for the Welcu API
|
85
|
+
test_files: []
|
data/.gitignore
DELETED
data/README.rdoc
DELETED
data/Rakefile
DELETED
data/lib/welcu.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'oauth2'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
require 'uri'
|
5
|
-
require "base64"
|
6
|
-
require "openssl"
|
7
|
-
|
8
|
-
require 'welcu/error'
|
9
|
-
require 'welcu/base'
|
10
|
-
require 'welcu/api'
|
11
|
-
require 'welcu/client'
|
12
|
-
|
13
|
-
module Welcu
|
14
|
-
DEFAULT_CONFIG = {
|
15
|
-
'welcu_uri' => 'https://backstage.welcu.com',
|
16
|
-
'api_path' => '/api/v1'
|
17
|
-
}.freeze
|
18
|
-
@config = DEFAULT_CONFIG
|
19
|
-
|
20
|
-
class << self
|
21
|
-
|
22
|
-
def load_config(yaml_file, scope = nil)
|
23
|
-
cfg = YAML::load(File.open(yaml_file))
|
24
|
-
if scope
|
25
|
-
cfg = cfg[scope]
|
26
|
-
end
|
27
|
-
|
28
|
-
config(cfg)
|
29
|
-
end
|
30
|
-
|
31
|
-
def config(values=nil)
|
32
|
-
if values
|
33
|
-
@config = @config.merge(values).freeze
|
34
|
-
end
|
35
|
-
|
36
|
-
@config
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
require 'welcu/railtie' if defined? Rails
|
data/lib/welcu/api.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
class API
|
3
|
-
attr_reader :client_id , :client_secret , :welcu_uri , :access_token , :consumer , :auth, :api_path
|
4
|
-
attr_accessor :locale, :administrator_id, :mode
|
5
|
-
alias_method :id, :client_id
|
6
|
-
alias_method :secret, :client_secret
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
options = Welcu.config.merge(options)
|
10
|
-
@client_id, @client_secret = options['client_id'], options['client_secret']
|
11
|
-
@welcu_uri = options['welcu_uri']
|
12
|
-
@api_path = options['api_path']
|
13
|
-
@access_token = options.fetch :access_token, nil
|
14
|
-
@auth = OAuth2::AccessToken.new(oauth_client , @access_token)
|
15
|
-
end
|
16
|
-
|
17
|
-
def access_token=(new_token)
|
18
|
-
@access_token = new_token
|
19
|
-
@auth = OAuth2::AccessToken.new(oauth_client , @access_token)
|
20
|
-
new_token
|
21
|
-
end
|
22
|
-
|
23
|
-
def oauth_client
|
24
|
-
OAuth2::Client.new(client_id, client_secret, :site => welcu_uri)
|
25
|
-
end
|
26
|
-
|
27
|
-
%w{get post put delete}.each do |method|
|
28
|
-
class_eval <<-EOM
|
29
|
-
def #{method}(path, *args)
|
30
|
-
JSON.parse( auth.#{method}(api_path+'/'+path+'.json',*args) )
|
31
|
-
end
|
32
|
-
EOM
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/welcu/base.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
class Base
|
3
|
-
attr_reader :attributes, :client
|
4
|
-
|
5
|
-
def initialize(client, attributes={})
|
6
|
-
@client = client
|
7
|
-
@attributes = attributes
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.attribute(*names)
|
11
|
-
names.each do |name|
|
12
|
-
self.class_eval <<-EOF
|
13
|
-
def #{name}
|
14
|
-
attributes['#{name}']
|
15
|
-
end
|
16
|
-
|
17
|
-
def #{name}=(value)
|
18
|
-
attributes['#{name}'] = value
|
19
|
-
end
|
20
|
-
EOF
|
21
|
-
end
|
22
|
-
end
|
23
|
-
attribute :id
|
24
|
-
|
25
|
-
def to_hash
|
26
|
-
{ self.class.name.gsub('Welcu::','').downcase => attributes }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/welcu/client.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
|
3
|
-
class Client < API
|
4
|
-
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
5
|
-
|
6
|
-
|
7
|
-
include Welcu::Client::Canvas
|
8
|
-
include Welcu::Client::Event
|
9
|
-
include Welcu::Client::Passes
|
10
|
-
include Welcu::Client::Registries
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
data/lib/welcu/client/canvas.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
|
3
|
-
module Welcu
|
4
|
-
class Client
|
5
|
-
module Canvas
|
6
|
-
def self.included(receiver)
|
7
|
-
receiver.extend ClassMethods
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def from_signed_request(request, options = {})
|
12
|
-
client = Welcu::Client.new(options)
|
13
|
-
signature, payload = request.split('.', 2)
|
14
|
-
|
15
|
-
data = Welcu::Client::Canvas.decode_payload(payload)
|
16
|
-
|
17
|
-
if data['algorithm'].to_s.upcase != 'HMAC-SHA256'
|
18
|
-
raise Welcu::Client::Canvas::BadSignatureAlgorithmError.new(data['algorithm'])
|
19
|
-
end
|
20
|
-
expected_sig = OpenSSL::HMAC.hexdigest('sha256', client.secret, payload)
|
21
|
-
|
22
|
-
if expected_sig != signature
|
23
|
-
raise Welcu::Client::Canvas::BadSignatureError
|
24
|
-
end
|
25
|
-
|
26
|
-
client.access_token = data['access_token']
|
27
|
-
client.mode = data['mode']
|
28
|
-
client.locale = data['locale']
|
29
|
-
client.administrator_id = data['administrator_id']
|
30
|
-
|
31
|
-
client
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.decode_payload(payload)
|
36
|
-
payload = payload.dup
|
37
|
-
payload << '=' until (payload.size % 4).zero?
|
38
|
-
JSON.parse(Base64.urlsafe_decode64(payload))
|
39
|
-
end
|
40
|
-
|
41
|
-
class BadSignatureError < Error; end
|
42
|
-
class BadSignatureAlgorithmError < Error; end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/welcu/client/event.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
class Client
|
3
|
-
module Event
|
4
|
-
def event
|
5
|
-
@event ||= Welcu::Event.new(self).load!
|
6
|
-
end
|
7
|
-
|
8
|
-
def company
|
9
|
-
event.company
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Event < Base
|
15
|
-
attr_accessor :company
|
16
|
-
|
17
|
-
attribute :name, :short_name, :permalink, :description, :starts_at, :ends_at, :locale, :logo, :location, :url, :logo_big
|
18
|
-
|
19
|
-
def load!
|
20
|
-
@attributes = client.get('event')['event']
|
21
|
-
self.company = Welcu::Company.new(self, @attributes.delete('company'))
|
22
|
-
self.company.event = self
|
23
|
-
client.locale ||= self.locale
|
24
|
-
self
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Company < Base
|
29
|
-
attr_accessor :event
|
30
|
-
attribute :name, :short_name, :permalink, :description, :locale
|
31
|
-
end
|
32
|
-
end
|
data/lib/welcu/client/passes.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
class Client
|
3
|
-
module Passes
|
4
|
-
def passes
|
5
|
-
@passes ||= Welcu::Client::Passes::Proxy.new(self)
|
6
|
-
end
|
7
|
-
|
8
|
-
class Proxy
|
9
|
-
include Enumerable
|
10
|
-
|
11
|
-
def initialize(client)
|
12
|
-
@client = client
|
13
|
-
end
|
14
|
-
|
15
|
-
def find(id)
|
16
|
-
passes.find { |p| p.id == id }
|
17
|
-
end
|
18
|
-
|
19
|
-
def [](poss)
|
20
|
-
passes[poss]
|
21
|
-
end
|
22
|
-
|
23
|
-
def each
|
24
|
-
passes.each { |p| yield p }
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
def passes
|
29
|
-
@passes ||= begin
|
30
|
-
@client.get('passes').map do |data|
|
31
|
-
Welcu::Pass.new(@client,data['pass'])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class Pass < Base
|
40
|
-
attr_reader :event
|
41
|
-
attribute :name, :description
|
42
|
-
|
43
|
-
def initialize(client, attributes={})
|
44
|
-
super
|
45
|
-
@event = client.event
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Welcu
|
2
|
-
class Client
|
3
|
-
module Registries
|
4
|
-
def registries
|
5
|
-
@registries ||= Welcu::Client::Registries::Proxy.new(self)
|
6
|
-
end
|
7
|
-
|
8
|
-
class Proxy
|
9
|
-
def initialize(client)
|
10
|
-
@client = client
|
11
|
-
end
|
12
|
-
|
13
|
-
def find(id)
|
14
|
-
data = @client.get("registries/#{id}")
|
15
|
-
Welcu::Registry.new(@client,data['registry'])
|
16
|
-
end
|
17
|
-
|
18
|
-
def build(attributes = {})
|
19
|
-
Welcu::Registry.new(@client,attributes)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Registry < Base
|
26
|
-
attr_reader :event
|
27
|
-
attribute :first_name, :last_name, :email, :phone, :pass_id
|
28
|
-
|
29
|
-
def initialize(client, attributes={})
|
30
|
-
super
|
31
|
-
@event = client.event
|
32
|
-
end
|
33
|
-
|
34
|
-
def pass
|
35
|
-
if pass_id
|
36
|
-
@pass ||= client.passes.find(pass_id)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def pass=(pass)
|
41
|
-
@pass = pass
|
42
|
-
self.pass_id = pass && pass.id
|
43
|
-
end
|
44
|
-
|
45
|
-
def save
|
46
|
-
if id
|
47
|
-
self.attributes = client.put("registries/#{id}", to_hash)['registry']
|
48
|
-
else
|
49
|
-
self.attributes = client.post("registries", to_hash)['registry']
|
50
|
-
end
|
51
|
-
|
52
|
-
true
|
53
|
-
end
|
54
|
-
|
55
|
-
def confirm!
|
56
|
-
client.put("/registries/#{id}/confirm")
|
57
|
-
true
|
58
|
-
end
|
59
|
-
|
60
|
-
def reject!
|
61
|
-
client.put("/registries/#{id}/reject")
|
62
|
-
true
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/welcu/error.rb
DELETED
data/lib/welcu/railtie.rb
DELETED
data/lib/welcu/version.rb
DELETED
data/spec/TODO
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
:P
|