ahub 0.11.5 → 0.12.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 +3 -3
- data/lib/ahub/modules/api_resource.rb +30 -5
- data/lib/ahub/question.rb +0 -4
- data/lib/ahub/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: da279c5c90296d752b2df975a0b9f00e8523ca99
|
4
|
+
data.tar.gz: 5a245b2a6fbc7b53903cf150b841beddcdc50335
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84b7c87bbc550306c313b535f37abb849388aac17dd8bf4bfb01921f3a0745f42da7586e3a7509771e90895895d7a286e4331f1f1a2a00e3b4e42009274f0266
|
7
|
+
data.tar.gz: d806049ccbac9db97409d5b716ce4b85030e3415e5177d5e40053489593de6719f833149a5d0b8e8769805e9c9275049d31aac773095a2f596378ea4772f6508
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Ahub
|
2
|
-
A gem to interact with the [Answer Hub API](docs.answerhubapiv2.apiary.io)
|
2
|
+
A gem to interact with the [Answer Hub API](http://docs.answerhubapiv2.apiary.io)
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/ahub.svg)](https://badge.fury.io/rb/ahub)
|
5
5
|
[![Build Status](https://travis-ci.org/abelmartin/ahub.svg?branch=master)](https://travis-ci.org/abelmartin/ahub)
|
@@ -38,9 +38,9 @@ AHUB_ENV_FILE=~/workspace/.ahub_env irb
|
|
38
38
|
|
39
39
|
## Development
|
40
40
|
|
41
|
-
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.
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` or simply `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
42
|
|
43
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
44
44
|
|
45
45
|
## Contributing
|
46
46
|
|
@@ -8,12 +8,10 @@ module Ahub
|
|
8
8
|
|
9
9
|
attr_reader :attributes
|
10
10
|
|
11
|
-
def update
|
12
|
-
raise NotImplementedError
|
13
|
-
end
|
14
|
-
|
15
11
|
def initialize(attrs)
|
16
|
-
@attributes
|
12
|
+
@attributes ||= {}
|
13
|
+
attrs.each_pair { |k,v| @attributes[k.to_sym] = v }
|
14
|
+
|
17
15
|
attrs.each_pair do |k,v|
|
18
16
|
attribute_name = k.to_s.underscore
|
19
17
|
|
@@ -29,6 +27,21 @@ module Ahub
|
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
30
|
+
def json_url
|
31
|
+
"#{self.class.base_url}/#{id}.json" if id
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
raise NotImplementedError
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_attribute(attribute, value)
|
39
|
+
payload = {}
|
40
|
+
payload[attribute] = value
|
41
|
+
|
42
|
+
self.class.update_resource(resource: self, payload: payload)
|
43
|
+
end
|
44
|
+
|
32
45
|
class_methods do
|
33
46
|
def headers(username:, password:)
|
34
47
|
encoded = "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
|
@@ -82,6 +95,18 @@ module Ahub
|
|
82
95
|
end
|
83
96
|
end
|
84
97
|
|
98
|
+
def update_resource(resource:, payload:)
|
99
|
+
raise Exception.new('#id is required for an update') unless resource.id
|
100
|
+
begin
|
101
|
+
response = RestClient.put(resource.json_url, payload.to_json, admin_headers)
|
102
|
+
resource.send(:initialize, JSON.parse(response))
|
103
|
+
payload.each{|k,v| resource.instance_variable_set("@#{k}", v) }
|
104
|
+
true
|
105
|
+
rescue Exception => e
|
106
|
+
false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
85
110
|
private
|
86
111
|
|
87
112
|
def create_resource(url:, payload:, headers:)
|
data/lib/ahub/question.rb
CHANGED
data/lib/ahub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abel Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|