devrant 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/devrant.rb +2 -2
- data/lib/devrant/api.rb +1 -0
- data/lib/devrant/rants.rb +8 -2
- data/lib/devrant/users.rb +11 -1
- data/lib/devrant/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6e50b28a0c9a1e0095331d0ac7946a8b33ca89
|
4
|
+
data.tar.gz: d48685c3ec0d15969d7112560f6d3f96de5e0cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a71d432d35379be2f9a334909a793483ba5bbb0a7305117ead8930706dcd66a0f45734e80c09cfd0c330e14e185671744bafe54053f94d3373ab64e2b8904294
|
7
|
+
data.tar.gz: 379fc583fb6d133f267fd155d52a8f47cb1c6ef7e758d185943ebf640410743e966527d99f31749512e443aeaa7b8dfb829bd9e6b49dab1a7063a76445ff569a
|
data/README.md
CHANGED
@@ -145,6 +145,25 @@ devRant = Devrant::Api.new
|
|
145
145
|
devRant.rants.random
|
146
146
|
```
|
147
147
|
|
148
|
+
**Commenting on a Rant**
|
149
|
+
|
150
|
+
Post a comment. You must authenticate before trying to post a comment.
|
151
|
+
|
152
|
+
|
153
|
+
| Method | Parameters |
|
154
|
+
|:--------|:-----------------------------------------------------------------------------------------|
|
155
|
+
|comment |rant_id (int), comment_content (string), token_id (int), token_key (string), user_id (int)|
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'devrant'
|
159
|
+
|
160
|
+
devRant = Devrant::Api.new
|
161
|
+
|
162
|
+
auth = devRant.users.authenticate('username', 'password')
|
163
|
+
|
164
|
+
devRant.rants.comment(12345, 'This is my comment', auth.id, auth.key, auth.user_id)
|
165
|
+
```
|
166
|
+
|
148
167
|
### Users
|
149
168
|
|
150
169
|
**Getting User by ID:**
|
@@ -167,6 +186,18 @@ devRant = Devrant::Api.new
|
|
167
186
|
devRant.users.get_user_id('RuntimeError')
|
168
187
|
```
|
169
188
|
|
189
|
+
**Authenticating a User**
|
190
|
+
|
191
|
+
Returns an auth object with a token id, token key, and user id.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
require 'devrant'
|
195
|
+
|
196
|
+
devRant = Devrant::Api.new
|
197
|
+
|
198
|
+
devRant.users.authenticate('username', 'password')
|
199
|
+
```
|
200
|
+
|
170
201
|
## Development
|
171
202
|
|
172
203
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/devrant.rb
CHANGED
@@ -12,8 +12,8 @@ module Devrant
|
|
12
12
|
JSON.parse(json.body, object_class: OpenStruct)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
{
|
15
|
+
def extend_request(var, options)
|
16
|
+
{ "#{var}": self.class.default_options[:query].merge(options) }
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
data/lib/devrant/api.rb
CHANGED
@@ -22,6 +22,7 @@ module Devrant
|
|
22
22
|
classes.each do |variable, classname|
|
23
23
|
self.instance_variable_set("@#{variable}", classname.new)
|
24
24
|
self.instance_variable_get("@#{variable}").class.default_options = HTTP_OPTIONS
|
25
|
+
self.instance_variable_get("@#{variable}").parent = self
|
25
26
|
self.singleton_class.class_eval do
|
26
27
|
attr_reader variable.to_sym
|
27
28
|
end
|
data/lib/devrant/rants.rb
CHANGED
@@ -3,6 +3,8 @@ module Devrant
|
|
3
3
|
include HTTParty
|
4
4
|
include Devrant
|
5
5
|
|
6
|
+
attr_accessor :parent
|
7
|
+
|
6
8
|
def all
|
7
9
|
structuralize(self.class.get('/devrant/rants')).rants
|
8
10
|
end
|
@@ -32,11 +34,15 @@ module Devrant
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def get_rants(params={})
|
35
|
-
structuralize(self.class.get('/devrant/rants',
|
37
|
+
structuralize(self.class.get('/devrant/rants', extend_request(:query, params))).rants
|
36
38
|
end
|
37
39
|
|
38
40
|
def search(term)
|
39
|
-
structuralize(self.class.get('/devrant/search',
|
41
|
+
structuralize(self.class.get('/devrant/search', extend_request(:query, {term: term}))).results
|
42
|
+
end
|
43
|
+
|
44
|
+
def comment(rant, content, token_id, token_key, user_id)
|
45
|
+
structuralize(self.class.post("/devrant/rants/#{rant}/comments", extend_request(:body, {token_id: token_id, token_key: token_key, user_id: user_id, comment: content})))
|
40
46
|
end
|
41
47
|
|
42
48
|
end
|
data/lib/devrant/users.rb
CHANGED
@@ -3,6 +3,8 @@ module Devrant
|
|
3
3
|
include HTTParty
|
4
4
|
include Devrant
|
5
5
|
|
6
|
+
attr_accessor :parent
|
7
|
+
|
6
8
|
def get_user_by_id(id)
|
7
9
|
user = structuralize(self.class.get("/users/#{id}")).profile
|
8
10
|
|
@@ -12,11 +14,19 @@ module Devrant
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def get_user_id(username)
|
15
|
-
id = structuralize(self.class.get('/get-user-id',
|
17
|
+
id = structuralize(self.class.get('/get-user-id', extend_request(:query, {username: username}))).user_id
|
16
18
|
|
17
19
|
return id unless id.nil?
|
18
20
|
|
19
21
|
raise ArgumentError.new("No user called #{username} found.")
|
20
22
|
end
|
23
|
+
|
24
|
+
def authenticate(username, password)
|
25
|
+
auth_token = structuralize(self.class.post("/users/auth-token", extend_request(:body, {username: username, password: password}))).auth_token
|
26
|
+
|
27
|
+
return auth_token unless auth_token.nil?
|
28
|
+
|
29
|
+
raise ArgumentError.new("Could not authenticate user #{username}")
|
30
|
+
end
|
21
31
|
end
|
22
32
|
end
|
data/lib/devrant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dovzhanyn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|