served 0.1.7 → 0.1.8

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: 9fc33f665810efb0338be77783f46f28a79604a3
4
- data.tar.gz: 9141fc737d07f6d9d8fdf235cbb3ac6dfd335a89
3
+ metadata.gz: 466e2def975e298806ecdef050c3c735823a3a95
4
+ data.tar.gz: 5ee4e6779cd2ec8f28c6121bb8e7b4a0a3e11f4d
5
5
  SHA512:
6
- metadata.gz: f38dae786e45652389e082659118258eb77d6bbccf34fe9f358321bfca0b2e416a7f7080c4523a6ccfa927fed2503e9aceb0d80b61755475c015eb71ed215658
7
- data.tar.gz: 15ac1e21e7e1557b53de03862cb3a622e3b0fa33618c010d64c0fa3545e3e9b3a7fdf809db0369bca22a1302c8755352691ff375145c16dd5e8296c0aafde22e
6
+ metadata.gz: 1ee891ea98ac7805ed1b5b39bb689131fd7c2fd46c693725f9eb8b2a43803d0df72e62b379be8293bf4a0291198fff1b1f7a8a4e3a48ba077a4074b18f345771
7
+ data.tar.gz: 78c97fc01bceaf808b868afee6a26bfc2206481c84e4d52457f97a8bfd2352a2bd8577e749c76a1bc87bf6079c48abcd5d9627caa73d90b441f76735280c7cab
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.8
4
+
5
+ * fix buggy GET request template expansion defaults
@@ -3,7 +3,7 @@ module Served
3
3
  # Provides an interface between HTTParty and the models. Most of the crap in here is self explanatory
4
4
  class HTTPClient
5
5
  HEADERS = { 'Content-type' => 'application/json', 'Accept' => 'application/json' }
6
- DEFAULT_TEMPLATE = '{resource}.json{?query*}'
6
+ DEFAULT_TEMPLATE = '{resource}{/id}.json{?query*}'
7
7
 
8
8
  def initialize(host)
9
9
  unless host =~ /{.+}/
@@ -12,15 +12,15 @@ module Served
12
12
  @template = Addressable::Template.new(host)
13
13
  end
14
14
 
15
- def get(endpoint, params={})
16
- HTTParty.get(@template.expand(query: params, resource: endpoint).to_s,
15
+ def get(endpoint, id, params={})
16
+ HTTParty.get(@template.expand(id: id, query: params, resource: endpoint).to_s,
17
17
  headers: HEADERS,
18
18
  timeout: Served.config.timeout
19
19
  )
20
20
  end
21
21
 
22
- def put(endpoint, body, params={})
23
- HTTParty.put(@template.expand(query: params, resource: endpoint).to_s,
22
+ def put(endpoint, id, body, params={})
23
+ HTTParty.put(@template.expand(id: id, query: params, resource: endpoint).to_s,
24
24
  body: body,
25
25
  headers: HEADERS,
26
26
  timeout: Served.config.timeout
@@ -94,9 +94,6 @@ module Served
94
94
 
95
95
  alias_method :save!, :save # TODO: differentiate save! and safe much the same AR does.
96
96
 
97
- # Returns a hash of attributes. If `with_values` is true, it will return only attributes whose values are not nil
98
- #
99
- # @param [Boolean] with_values whether or not to return all attributes or only those whose values are not nil
100
97
  def attributes
101
98
  Hash[self.class.attributes.keys.collect { |name| [name, send(name)] }]
102
99
  end
@@ -104,6 +101,7 @@ module Served
104
101
  # Reloads the resource using attributes from the service
105
102
  def reload
106
103
  reload_with_attributes(get)
104
+ self
107
105
  end
108
106
 
109
107
  # renders the model as json
@@ -121,17 +119,17 @@ module Served
121
119
  private
122
120
 
123
121
  def get(params={})
124
- handle_response(client.get("#{resource_name}/#{id}", params))
122
+ handle_response(client.get(resource_name, id, params))
125
123
  end
126
124
 
127
125
  def put(params={})
128
126
  body = to_json
129
- handle_response(client.put("#{resource_name}/#{id}", body, params))
127
+ handle_response(client.put(resource_name, id, body, params))
130
128
  end
131
129
 
132
130
  def post(params={})
133
131
  body = to_json
134
- handle_response(client.post("#{resource_name}", body, params))
132
+ handle_response(client.post(resource_name, body, params))
135
133
  end
136
134
 
137
135
  def handle_response(response)
@@ -1,3 +1,3 @@
1
1
  module Served
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: served
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarod Reid
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -105,6 +105,7 @@ files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
107
  - ".travis.yml"
108
+ - CHANGELOG.md
108
109
  - CODE_OF_CONDUCT.md
109
110
  - Gemfile
110
111
  - LICENSE.txt