hullio 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +34 -1
- data/lib/hull.rb +4 -0
- data/lib/hull/client.rb +3 -2
- data/lib/hull/config.rb +1 -0
- data/lib/hull/middlewares/hook.rb +44 -0
- data/lib/hull/request/auth.rb +2 -1
- data/lib/hull/version.rb +1 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,8 @@ Or install it yourself as:
|
|
24
24
|
c.org_url = "http://ORG-NAMESPACE.hullapp.io"
|
25
25
|
end
|
26
26
|
|
27
|
+
In Rails, you can include this in an initializer.
|
28
|
+
|
27
29
|
### Making API Calls
|
28
30
|
|
29
31
|
`get`, `put`, `post` and `delete` methods are directly available on Hull.
|
@@ -46,7 +48,38 @@ with Hull entities :
|
|
46
48
|
Hull.delete('entity', { uid: 'http://example.com' })
|
47
49
|
|
48
50
|
|
49
|
-
###
|
51
|
+
### Making API calls as as a User
|
52
|
+
|
53
|
+
From its user ID
|
54
|
+
|
55
|
+
Hull.as('51fa7afd09e50d11f1000002').get('me')
|
56
|
+
|
57
|
+
From a user UID
|
58
|
+
|
59
|
+
Hull.as('twitter:hull').get('me')
|
60
|
+
Hull.as('external:3637').get('me')
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
### Getting the current User
|
65
|
+
|
66
|
+
Hull.authenticate_user allows you to get the current User's ID.
|
67
|
+
|
68
|
+
#### Rails
|
69
|
+
|
70
|
+
|
71
|
+
class MyController < ApplicationController
|
72
|
+
def current_hull_user_id
|
73
|
+
@current_hull_user_id ||= Hull.authenticate_user(request.env)
|
74
|
+
end
|
75
|
+
def current_hull_user
|
76
|
+
// You probably should cache this or record this information in a session
|
77
|
+
// to avoid making calls to Hull's API on each request
|
78
|
+
@current_hull_user ||= Hull.get(current_hull_user_id)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
### Compiling widgets and templates with Rails' Assets Pipeline
|
50
83
|
|
51
84
|
Load `handlebars_assets` in your Gemfile as part of the assets group
|
52
85
|
|
data/lib/hull.rb
CHANGED
data/lib/hull/client.rb
CHANGED
data/lib/hull/config.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rack/request'
|
3
|
+
|
4
|
+
module Hull::Middlewares
|
5
|
+
class Hook
|
6
|
+
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def initialize app, options={}, &handler
|
10
|
+
@app = app
|
11
|
+
@options = options
|
12
|
+
if block_given?
|
13
|
+
@handler = handler
|
14
|
+
elsif options[:handler]
|
15
|
+
@handler = options[:handler]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def call env
|
20
|
+
path = options[:path] || "/__hull-hooks__"
|
21
|
+
if env['PATH_INFO'] == path && valid?(env)
|
22
|
+
begin
|
23
|
+
request = Rack::Request.new(env)
|
24
|
+
event = JSON.parse(request.body.read)
|
25
|
+
response = (@handler.call(event, request) || "ok").to_s
|
26
|
+
[200, { 'Content-Type' => 'text/html' }, [response]]
|
27
|
+
rescue => err
|
28
|
+
[500, { 'Content-Type' => 'text/html' }, ["Invalid Request: #{err.inspect}"]]
|
29
|
+
end
|
30
|
+
else
|
31
|
+
@app.call(env)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid? env
|
36
|
+
body = env['rack.input'].read
|
37
|
+
env['rack.input'].rewind
|
38
|
+
timestamp, nonce, signature = (env['HTTP_HULL_SIGNATURE'] || "").split('.')
|
39
|
+
data = [timestamp, nonce, body].join("-")
|
40
|
+
signature == OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), options[:secret], data)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/hull/request/auth.rb
CHANGED
@@ -6,7 +6,8 @@ module Hull
|
|
6
6
|
|
7
7
|
def call(env)
|
8
8
|
env[:request_headers]["Hull-Access-Token"] = @credentials[:app_secret]
|
9
|
-
env[:request_headers]["Hull-App-
|
9
|
+
env[:request_headers]["Hull-App-Id"] = @credentials[:app_id]
|
10
|
+
env[:request_headers]["Hull-User-Id"] = @credentials[:user_id] if @credentials[:user_id]
|
10
11
|
@app.call(env)
|
11
12
|
end
|
12
13
|
|
data/lib/hull/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hullio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/hull/config.rb
|
117
117
|
- lib/hull/connection.rb
|
118
118
|
- lib/hull/core_ext/hash.rb
|
119
|
+
- lib/hull/middlewares/hook.rb
|
119
120
|
- lib/hull/paywall.rb
|
120
121
|
- lib/hull/request.rb
|
121
122
|
- lib/hull/request/auth.rb
|
@@ -146,4 +147,3 @@ signing_key:
|
|
146
147
|
specification_version: 3
|
147
148
|
summary: Hull Ruby Client
|
148
149
|
test_files: []
|
149
|
-
has_rdoc:
|