unloq 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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/lib/unloq.rb +12 -0
- data/lib/unloq/api_error.rb +17 -0
- data/lib/unloq/client.rb +80 -0
- data/lib/unloq/entities/author.rb +5 -0
- data/lib/unloq/entities/recipient.rb +5 -0
- data/lib/unloq/entity.rb +15 -0
- data/lib/unloq/events.rb +28 -0
- data/lib/unloq/version.rb +3 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94a280dda4b4c3f7cacaa84a69ac967338e71c46
|
4
|
+
data.tar.gz: 0a4eb6f0d22a3a0572d5a12ae21ee82203990548
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59ca0165dd20edcddf0fcfbca4906e3289df3d8fa7cae99974f42ec61ed957a67f92f391aa44212dd6d40467704275e0253a5de97341e5a5a9b9060d2ec2f089
|
7
|
+
data.tar.gz: 265f1581b9ca612941d84834a6fae99796096e6d5a842ff14ab97fcfce7a0e387b0921aa46b8e63b508b69780be11b3ebe76f2fcdcbf944bdffd4ccba991e766
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 mattmueller
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
unloq
|
2
|
+
=====
|
3
|
+
|
4
|
+
Ruby wrapper for the Unloq API.
|
5
|
+
|
6
|
+
Both this library as well as portions of the Unloq API are in active development, please keep this in mind when implementing.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
gem install unloq
|
11
|
+
|
12
|
+
Or add it to your Gemfile
|
13
|
+
|
14
|
+
gem 'unloq'
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Instantiate an instance of Unloq::Client
|
19
|
+
|
20
|
+
This can be used for all requests within the scope of a given `api_key` and `namespace` - it should not need to be instantiated each time you make an API call.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
client = Unloq::Client.new(api_key: 'your-api-key', namespace: 'foo-dev')
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
### Events
|
28
|
+
|
29
|
+
Create an event:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
author = Unloq::Author.new(id: 12, type: 'User')
|
33
|
+
recipient = Unloq::Recipient.new(id: 13, type: 'User')
|
34
|
+
|
35
|
+
client.create_event(author, 'followed', recipient)
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
## Documentation
|
40
|
+
|
41
|
+
See [the documentation](http://rubydoc.info/gems/unloq/frames)
|
42
|
+
|
data/lib/unloq.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#External libs
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
#Unloq Classes
|
6
|
+
require 'unloq/version'
|
7
|
+
require 'unloq/api_error'
|
8
|
+
require 'unloq/entity'
|
9
|
+
require 'unloq/entities/author'
|
10
|
+
require 'unloq/entities/recipient'
|
11
|
+
require 'unloq/events'
|
12
|
+
require 'unloq/client'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Unloq
|
2
|
+
class APIError < StandardError
|
3
|
+
|
4
|
+
attr_reader :status, :body
|
5
|
+
|
6
|
+
def initialize(status, body)
|
7
|
+
@status = status
|
8
|
+
@body = body
|
9
|
+
super(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"status_code:#{status} body:#{body.inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/unloq/client.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Unloq
|
2
|
+
class Client
|
3
|
+
|
4
|
+
include Events
|
5
|
+
|
6
|
+
attr_reader :api_key, :namespace
|
7
|
+
|
8
|
+
# Initialize the client class that will be used for all Unloq interactions.
|
9
|
+
#
|
10
|
+
# @param [String] api_key Your Unloq api key.
|
11
|
+
# @param [String] namespace The namespace under which Unloq events should be created, e.g. appname-dev
|
12
|
+
|
13
|
+
def initialize api_key: nil, namespace: nil
|
14
|
+
unless api_key && namespace
|
15
|
+
raise ArgumentError.new("You must include both an api_key and namespace, e.g. Unloq::Client.new(api_key: 'foo', namespace: 'bar')")
|
16
|
+
end
|
17
|
+
|
18
|
+
@api_key = api_key
|
19
|
+
@namespace = namespace
|
20
|
+
end
|
21
|
+
|
22
|
+
# Make a post request to the Unloq API
|
23
|
+
#
|
24
|
+
# @param [String] endpoint The resource endpoint, e.g. /events
|
25
|
+
# @param [Hash] body The body payload that should be POSTed
|
26
|
+
|
27
|
+
def post endpoint, body = {}
|
28
|
+
body.merge!(api_key: api_key, namespace: namespace)
|
29
|
+
|
30
|
+
response = connection.post do |req|
|
31
|
+
req.url endpoint
|
32
|
+
req.body = body.to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
format_response_or_raise_error(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Validate that any author used is of the appropriate type
|
40
|
+
def validate_author author
|
41
|
+
raise ArgumentError.new("Author must be an Unloq::Author or Unloq::Recipient") unless author.is_a?(Unloq::Entity)
|
42
|
+
end
|
43
|
+
|
44
|
+
#Validate that any recipient used is of the appropriate type
|
45
|
+
def validate_recipient recipient
|
46
|
+
raise ArgumentError.new("Recipient must be an Unloq::Author or Unloq::Recipient") unless recipient.is_a?(Unloq::Entity)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Return either the response body or raise a helpful error
|
52
|
+
|
53
|
+
def format_response_or_raise_error response
|
54
|
+
if response.status / 100 == 2
|
55
|
+
response.body
|
56
|
+
else
|
57
|
+
raise Unloq::APIError.new(response.status, response.body)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Set up basics of all HTTP connections for Unloq api requests
|
62
|
+
|
63
|
+
def connection
|
64
|
+
@connection ||= Faraday.new(url: 'http://api.unloq.co', headers: default_headers) do |conn|
|
65
|
+
conn.request :json
|
66
|
+
conn.adapter Faraday.default_adapter
|
67
|
+
conn.response :json, :content_type => /\bjson$/
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set default headers for all requests
|
72
|
+
|
73
|
+
def default_headers
|
74
|
+
{
|
75
|
+
user_agent: "Unloq ruby gem #{Unloq::VERSION}"
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/unloq/entity.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Unloq
|
2
|
+
class Entity
|
3
|
+
attr_reader :id, :type, :meta
|
4
|
+
|
5
|
+
def initialize id: nil, type: nil, meta: {}
|
6
|
+
unless id && type
|
7
|
+
raise ArgumentError.new("You must include both an id and a type, e.g. #{self.class.to_s}.new(id: 1, type: 'User')")
|
8
|
+
end
|
9
|
+
|
10
|
+
@id = id
|
11
|
+
@type = type
|
12
|
+
@meta = meta
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/unloq/events.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Unloq
|
2
|
+
module Events
|
3
|
+
|
4
|
+
# Create an event via the Unloq API
|
5
|
+
#
|
6
|
+
# @param [Unloq::Entity] author Author involved in the event
|
7
|
+
# @param [String] verb The verb of the event
|
8
|
+
# @param [Unloq::Entity] recipient Recipient involved in the event
|
9
|
+
# @param [Hash] meta A hash of additional metadata to send with the request
|
10
|
+
|
11
|
+
def create_event author, verb, recipient, meta = {}
|
12
|
+
validate_author(author)
|
13
|
+
validate_recipient(recipient)
|
14
|
+
|
15
|
+
body_to_post = {
|
16
|
+
author_id: author.id,
|
17
|
+
author_type: author.type,
|
18
|
+
recipient_id: recipient.id,
|
19
|
+
recipient_type: recipient.type,
|
20
|
+
verb: verb,
|
21
|
+
meta: meta
|
22
|
+
}
|
23
|
+
|
24
|
+
post('/events', body_to_post)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unloq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Mueller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.18'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.18'
|
125
|
+
description: Ruby gem for interacting with the Unloq API. See http://www.unloq.co/api_docs/index
|
126
|
+
for more information.
|
127
|
+
email: muellermr@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE
|
134
|
+
- README.md
|
135
|
+
- lib/unloq.rb
|
136
|
+
- lib/unloq/api_error.rb
|
137
|
+
- lib/unloq/client.rb
|
138
|
+
- lib/unloq/entities/author.rb
|
139
|
+
- lib/unloq/entities/recipient.rb
|
140
|
+
- lib/unloq/entity.rb
|
141
|
+
- lib/unloq/events.rb
|
142
|
+
- lib/unloq/version.rb
|
143
|
+
homepage: http://github.com/mattmueller/unloq
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.2.2
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Ruby gem for interacting with the Unloq API.
|
167
|
+
test_files: []
|