welcu 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +3 -0
- data/Rakefile +2 -0
- data/lib/welcu.rb +41 -0
- data/lib/welcu/api.rb +35 -0
- data/lib/welcu/base.rb +29 -0
- data/lib/welcu/client.rb +13 -0
- data/lib/welcu/client/canvas.rb +45 -0
- data/lib/welcu/client/event.rb +32 -0
- data/lib/welcu/client/passes.rb +48 -0
- data/lib/welcu/client/registries.rb +65 -0
- data/lib/welcu/error.rb +3 -0
- data/lib/welcu/railtie.rb +8 -0
- data/lib/welcu/version.rb +3 -0
- data/spec/TODO +1 -0
- data/welcu.gemspec +27 -0
- metadata +134 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
data/Rakefile
ADDED
data/lib/welcu.rb
ADDED
@@ -0,0 +1,41 @@
|
|
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
ADDED
@@ -0,0 +1,35 @@
|
|
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
ADDED
@@ -0,0 +1,29 @@
|
|
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
ADDED
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,45 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,48 @@
|
|
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
|
@@ -0,0 +1,65 @@
|
|
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
ADDED
data/spec/TODO
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
:P
|
data/welcu.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'base64'
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "welcu/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "welcu"
|
8
|
+
s.version = Welcu::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Sebastian Gamboa"]
|
11
|
+
s.email = [ Base64.decode64("c2ViYUB3ZWxjdS5jb20=\n") ]
|
12
|
+
s.homepage = "http://github.com/welcu/welcu.gem"
|
13
|
+
s.summary = "A Gem for the Welcu API"
|
14
|
+
s.description = "A Gem for the Welcu API"
|
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) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency("oauth2", '0.1.1')
|
23
|
+
s.add_runtime_dependency("json")
|
24
|
+
|
25
|
+
s.add_development_dependency("rake")
|
26
|
+
s.add_development_dependency("bundler")
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: welcu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Sebastian Gamboa
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-20 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: oauth2
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 1
|
32
|
+
version: 0.1.1
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
description: A Gem for the Welcu API
|
75
|
+
email:
|
76
|
+
- seba@welcu.com
|
77
|
+
executables: []
|
78
|
+
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files: []
|
82
|
+
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- Gemfile
|
86
|
+
- README.rdoc
|
87
|
+
- Rakefile
|
88
|
+
- lib/welcu.rb
|
89
|
+
- lib/welcu/api.rb
|
90
|
+
- lib/welcu/base.rb
|
91
|
+
- lib/welcu/client.rb
|
92
|
+
- lib/welcu/client/canvas.rb
|
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
|
100
|
+
- welcu.gemspec
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/welcu/welcu.gem
|
103
|
+
licenses: []
|
104
|
+
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.3.7
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: A Gem for the Welcu API
|
133
|
+
test_files:
|
134
|
+
- spec/TODO
|