json_api_client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5dc30d75271f775fd27639171b3b4dfd4b9da7b
4
- data.tar.gz: 2418ed2aa0e612ed311a8be1aa7034ee97c0c087
3
+ metadata.gz: b850c5b674039c387b45ecaa49c4800a667bf503
4
+ data.tar.gz: b0a12cdba47effcf2e5708a64852445dc77b494c
5
5
  SHA512:
6
- metadata.gz: 57fdb0d9bf05f2bb85680c09f9d7450b1d5d88a4181bf898b3aa7ecce83e0b9296df743983c2330f673feedbafa9d70fc3b8d8227f1e9cb28605faeddbdc5b6f
7
- data.tar.gz: 15784232886469995b4222ff8582e49e5b1a8f19bef800f6286e41b1320265309a88c2fa82322e7c29a4042bab3b2c785ada11e8858e66a22a293d602b11f9e3
6
+ metadata.gz: f4f52b341ab65f8993f90c347d0d114c91f1ab269d018190f3e937c38f08c19c725d1be84ef0751364c9b3655536556b05b5a928e19c251deb69c9a0cfa86e89
7
+ data.tar.gz: d5df64cc6493f06792596c879bad18f031398bc306a6c8fe179d97ff10d8ffc2ce1fc032875b39e4fd030e70265cd4791a0edbc2f1964182a5df783bdaae9a15
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # JsonApiClient [![Build Status](https://travis-ci.org/chingor13/json_api_client.png)](https://travis-ci.org/chingor13/json_api_client)
1
+ # JsonApiClient [![Build Status](https://travis-ci.org/chingor13/json_api_client.png)](https://travis-ci.org/chingor13/json_api_client) [![Code Climate](https://codeclimate.com/github/chingor13/json_api_client.png)](https://codeclimate.com/github/chingor13/json_api_client) [![Code Coverage](https://codeclimate.com/github/chingor13/json_api_client/coverage.png)](https://codeclimate.com/github/chingor13/json_api_client)
2
2
 
3
3
  This gem is meant to help you build an API client for interacting with REST APIs as laid out by [http://jsonapi.org](http://jsonapi.org). It attempts to give you a query building framework that is easy to understand (it is similar to ActiveRecord scopes).
4
4
 
@@ -115,4 +115,4 @@ module MyApi
115
115
  end
116
116
 
117
117
 
118
- ```
118
+ ```
@@ -19,7 +19,7 @@ module JsonApiClient
19
19
  end
20
20
 
21
21
  def build_params(args)
22
- @params = args
22
+ @params = args.dup
23
23
  end
24
24
 
25
25
  end
@@ -32,7 +32,10 @@ module JsonApiClient
32
32
 
33
33
  def create(conditions = {})
34
34
  result = run_request(Query::Create.new(self, conditions))
35
- return nil if result.errors.length > 0
35
+ if result.has_errors?
36
+ yield(result) if block_given?
37
+ return nil
38
+ end
36
39
  result.first
37
40
  end
38
41
 
@@ -58,20 +61,30 @@ module JsonApiClient
58
61
  end
59
62
 
60
63
  def destroy
61
- run_request(Query::Destroy.new(self.class, attributes))
64
+ if run_request(Query::Destroy.new(self.class, attributes))
65
+ self.attributes.clear
66
+ true
67
+ else
68
+ false
69
+ end
62
70
  end
63
71
 
64
72
  protected
65
73
 
66
74
  def run_request(query)
67
- response = self.class.run_request(query)
68
- self.errors = response.errors
69
- if updated = response.first
70
- self.attributes = updated.attributes
75
+ # reset errors if a new request is being made
76
+ self.errors.clear if self.errors
77
+
78
+ result = self.class.run_request(query)
79
+ self.errors = result.errors
80
+ if result.has_errors?
81
+ return false
71
82
  else
72
- self.attributes = {}
83
+ if updated = result.first
84
+ self.attributes = updated.attributes
85
+ end
86
+ return true
73
87
  end
74
- return errors.length == 0
75
88
  end
76
89
 
77
90
  end
@@ -9,5 +9,9 @@ module JsonApiClient
9
9
  yield(result_set) if block_given?
10
10
  end
11
11
  end
12
+
13
+ def has_errors?
14
+ errors && errors.length > 0
15
+ end
12
16
  end
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.2.0
129
+ rubygems_version: 2.2.2
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: Build client libraries compliant with specification defined by jsonapi.org