hullio 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,11 +18,13 @@ Or install it yourself as:
18
18
 
19
19
  ### Configuration
20
20
 
21
- Hull.configure do |c|
22
- c.app_id = "your-app-id"
23
- c.app_secret = "your-app-secret"
24
- c.org_url = "http://ORG-NAMESPACE.hullapp.io"
25
- end
21
+ ```rb
22
+ Hull.configure do |c|
23
+ c.app_id = "your-app-id"
24
+ c.app_secret = "your-app-secret"
25
+ c.org_url = "http://ORG-NAMESPACE.hullapp.io"
26
+ end
27
+ ```
26
28
 
27
29
  In Rails, you can include this in an initializer.
28
30
 
@@ -30,63 +32,67 @@ In Rails, you can include this in an initializer.
30
32
 
31
33
  `get`, `put`, `post` and `delete` methods are directly available on Hull.
32
34
 
33
- examples:
35
+ examples:
34
36
 
35
- # To get the current app
36
- Hull.get('app')
37
+ ```rb
38
+ # To get the current app
39
+ Hull.get('app')
37
40
 
38
- # To get the a list of comments on the current app (with pagination)
39
- Hull.get('app/comments', limit: 10, page: 2)
41
+ # To get the a list of comments on the current app (with pagination)
42
+ Hull.get('app/comments', limit: 10, page: 2)
40
43
 
41
- # To update an existing object
42
- Hull.put('app', { name: 'My Super App' })
44
+ # To update an existing object
45
+ Hull.put('app', { name: 'My Super App' })
46
+ ```
43
47
 
44
48
  with Hull entities :
45
49
 
46
- Hull.get('entity', { uid: 'http://example.com' })
47
- Hull.put('entity', { uid: 'http://example.com', name: 'My super Page' })
48
- Hull.delete('entity', { uid: 'http://example.com' })
49
-
50
+ ```rb
51
+ Hull.get('entity', { uid: 'http://example.com' })
52
+ Hull.put('entity', { uid: 'http://example.com', name: 'My super Page' })
53
+ Hull.delete('entity', { uid: 'http://example.com' })
54
+ ```
50
55
 
51
56
  ### Making API calls as as a User
52
57
 
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
-
58
+ ```rb
59
+ # From its user ID
60
+ Hull.as('51fa7afd09e50d11f1000002').get('me')
62
61
 
62
+ # From a user UID
63
+ Hull.as('twitter:hull').get('me')
64
+ Hull.as('external:3637').get('me')
65
+ ```
63
66
 
64
67
  ### Getting the current User
65
68
 
66
- Hull.authenticate_user allows you to get the current User's ID.
69
+ `Hull.authenticate_user` allows you to get the current User's ID.
67
70
 
68
71
  #### Rails
69
72
 
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
73
+ ```rb
74
+ class MyController < ApplicationController
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
+
81
+ def current_hull_user_id
82
+ @current_hull_user_id ||= Hull.authenticate_user(request.env)
83
+ end
84
+ end
85
+ ```
81
86
 
82
87
  ### Compiling widgets and templates with Rails' Assets Pipeline
83
88
 
84
89
  Load `handlebars_assets` in your Gemfile as part of the assets group
85
90
 
86
- group :assets do
87
- gem 'handlebars_assets'
88
- end
89
-
91
+ ```rb
92
+ group :assets do
93
+ gem 'handlebars_assets'
94
+ end
95
+ ```
90
96
 
91
97
  Place your widgets inside the `app/assets/javascripts` dir.
92
98
 
@@ -100,28 +106,42 @@ Place your widgets inside the `app/assets/javascripts` dir.
100
106
 
101
107
  And require the in your `application.js` file :
102
108
 
103
-
104
- //= require handlebars
105
- //= require_tree .
106
-
109
+ ```js
110
+ //= require handlebars
111
+ //= require_tree .
112
+ ```
107
113
 
108
114
  ### Bring your own users
109
115
 
110
116
  In addition to providing multiple social login options, Hull allows you to create and authenticate users that are registered within your own app.
111
117
 
112
- To use this feature, you just have to add a `userHash` key at the initialization of hull.js :
118
+ To use this feature, you just have to add a `userHash` key at the initialization of hull.js :
119
+
120
+ In you view :
121
+
122
+ ```html
123
+ <script>
124
+ Hull.init({
125
+ appId: "<%= Hull.app_id %>",
126
+ orgUrl: "<%= Hull.org_url %>",
127
+ userHash: "<%= Hull.user_hash({ id: "123", email: "bill@hullapp.io", name: "Bill Evans" }) %>"
128
+ });
129
+ </script>
130
+ ```
113
131
 
114
- In you view :
132
+ ### Hooks
115
133
 
116
- <script>
117
- Hull.init({
118
- appId: "<%= Hull.app_id %>",
119
- orgUrl: "<%= Hull.org_url %>",
120
- userHash: "<%= Hull.user_hash({ id: "123", email: "bill@hullapp.io", name: "Bill Evans" }) %>"
121
- });
122
- </script>
134
+ [Hooks](hull.io/docs/libraries/#hooks) allow you to be notified every time an
135
+ object in your app is created, updated or deleted.
123
136
 
137
+ ```ruby
138
+ require 'hull/middlewares/hook'
124
139
 
140
+ # path option default is '/__hull-hook__'
141
+ use Hull::Middlewares::Hook, path: '/hullook', secret: ENV['HULL_APP_SECRET'] do |event, request|
142
+ # Do something with event
143
+ end
144
+ ```
125
145
 
126
146
  ## Contributing
127
147
 
@@ -1,7 +1,9 @@
1
1
  module Hull
2
2
  # Defines HTTP request methods
3
3
  module Request
4
-
4
+ API_PATH_REGEXP = /^\/?api\/v1\//
5
+ API_PATH = '/api/v1/'
6
+
5
7
  # Perform an HTTP DELETE request
6
8
  def delete(path, params={}, options={})
7
9
  request(:delete, api_path(path), params, options)
@@ -22,13 +24,13 @@ module Hull
22
24
  request(:put, api_path(path), params, options)
23
25
  end
24
26
 
25
- private
27
+ private
26
28
 
27
- def api_path path
28
- if path =~ /^\//
29
- path.to_s
29
+ def api_path(path)
30
+ if path =~ API_PATH_REGEXP
31
+ path.gsub(API_PATH_REGEXP, API_PATH)
30
32
  else
31
- "/api/v1/#{path.to_s.gsub(/^\//, '')}"
33
+ API_PATH + (path[0] == '/' ? path[1..-1] : path)
32
34
  end
33
35
  end
34
36
 
@@ -47,6 +49,5 @@ module Hull
47
49
  end
48
50
  options[:raw] ? response : response.body
49
51
  end
50
-
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module Hull
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
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.3.1
4
+ version: 0.3.2
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-11-18 00:00:00.000000000 Z
13
+ date: 2014-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday