ahub 0.11.5 → 0.12.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a118d6102ba7c381e70b546095a81a6e611266dc
4
- data.tar.gz: 55c0a6085ce0851ae2648a9b434d453c5e1b1f8b
3
+ metadata.gz: da279c5c90296d752b2df975a0b9f00e8523ca99
4
+ data.tar.gz: 5a245b2a6fbc7b53903cf150b841beddcdc50335
5
5
  SHA512:
6
- metadata.gz: 36edf105ba65ba6f320f5e8fdf65f09bb088d9a8cef3e451a298c94645b20a0a529f52bc4e941ed73897f97192b2e7b0408b8f04691df7c94b22e7b206eb4864
7
- data.tar.gz: 5437fdb8963425ad907b0eea192e1b06ae2e5981ef170e67c27ab178ffe917aec1c54cdc7dfec4d1c43fc17d6c47a0b6135d552704fbdf2e7402f9d4dd801161
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 = attrs
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:)
@@ -49,10 +49,6 @@ module Ahub
49
49
  "#{Ahub::DOMAIN}/questions/#{id}/#{slug}.html" if id
50
50
  end
51
51
 
52
- def json_url
53
- "#{self.class.base_url}/#{id}.json" if id
54
- end
55
-
56
52
  def to_s
57
53
  html_url
58
54
  end
@@ -1,3 +1,3 @@
1
1
  module Ahub
2
- VERSION = "0.11.5"
2
+ VERSION = "0.12.0"
3
3
  end
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.11.5
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-28 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client