ncore 1.1.0 → 1.2.0

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: fc0cd2d836140813317acebb7edd9b8adabf96c3
4
- data.tar.gz: ae9dec97a381f7ec33f6787b392a279e93fd8802
3
+ metadata.gz: ef94f6b1037f27d30294786117a465ad2f884c18
4
+ data.tar.gz: 105361f8d4f0cc2639078bc48053d20ddaa6e9f1
5
5
  SHA512:
6
- metadata.gz: 7391569e6594e7e37ad20360c7da20a5ca1383712ddc14ff075c2e486d9d9ccb920a2af87430557eb63b7b01d048380e19fc8352e1466f9bf8f4c9bb82f57a01
7
- data.tar.gz: e1989c0fdd27354b892245adc38aefb3f75a664e7bc81e5d038b449287eb221fcd8b2a44f83755b33cab82969f5f3f0879530f0e4a0b8e3feb3965789add2c60
6
+ metadata.gz: 14c748af57d663dcf4b7881e1ed6cda3df04105310a3858095e853bc7be8f5b1cd9016ec5c10f498b1de0736f3b501658947ed490f906c219461938378266d0a
7
+ data.tar.gz: 311dee415e76cbb165e19114502b47124b1c5c9d8cc819ca8998e9b8d59cafe8efd2c4cf3bf52a1e6336950f036e22d412907198f90580e736891d1a73d97ac2
@@ -20,8 +20,6 @@ module NCore
20
20
  class_eval <<-M2, __FILE__, __LINE__+1
21
21
  def find_#{assoc.singularize}(aid, params={})
22
22
  raise UnsavedObjectError unless id
23
- ## #{assoc}.detect{|o| o.id == aid} || raise(RecordNotFound)
24
- # @attribs[:#{assoc}].detect{|o| o.id == aid} || #{klass}.find(aid, {#{key}: id}, api_creds)
25
23
  #{klass}.find(aid, {#{key}: id}.reverse_merge(params), api_creds)
26
24
  end
27
25
  M2
@@ -38,6 +36,8 @@ module NCore
38
36
  obj = find_#{assoc.singularize}(aid)
39
37
  obj.update(params)
40
38
  obj
39
+ # raise UnsavedObjectError unless id
40
+ # #{klass}.update(aid, {#{key}: id}.reverse_merge(params), api_creds)
41
41
  end
42
42
  M4
43
43
  class_eval <<-M5, __FILE__, __LINE__+1
@@ -52,8 +52,52 @@ module NCore
52
52
  obj.save!(params)
53
53
  end
54
54
  M6
55
+ # will always return the object; check .errors? or .valid? to see how it went
56
+ class_eval <<-M7, __FILE__, __LINE__+1
57
+ def delete_#{assoc.singularize}(aid, params={})
58
+ obj = find_#{assoc.singularize}(aid)
59
+ obj.delete(params)
60
+ obj
61
+ # raise UnsavedObjectError unless id
62
+ # #{klass}.delete(aid, {#{key}: id}.reverse_merge(params), api_creds)
63
+ end
64
+ M7
65
+ class_eval <<-M8, __FILE__, __LINE__+1
66
+ def delete_#{assoc.singularize}!(aid, params={})
67
+ raise UnsavedObjectError unless id
68
+ #{klass}.delete!(aid, {#{key}: id}.reverse_merge(params), api_creds)
69
+ end
70
+ M8
55
71
  end
56
72
 
73
+ # def embeds_many(assoc)
74
+ # assoc = assoc.to_s
75
+ # class_eval <<-M1, __FILE__, __LINE__+1
76
+ # def #{assoc}(params={})
77
+ # @attribs[:#{assoc}] ||= []
78
+ # end
79
+ # M1
80
+ # class_eval <<-M2, __FILE__, __LINE__+1
81
+ # def find_#{assoc.singularize}(aid)
82
+ # #{assoc}.detect{|o| o.id == aid} || raise(RecordNotFound)
83
+ # end
84
+ # M2
85
+ #
86
+ # # appease activerecord:
87
+ # class_eval <<-M3, __FILE__, __LINE__+1
88
+ # def #{assoc}_attributes=(v)
89
+ # v = v.values if v.is_a?(Hash)
90
+ # if v.is_a?(Array)
91
+ # v.each{|o| o['object'] ||= '#{assoc.singularize}' if o.is_a?(Hash) }
92
+ # @attribs[:#{assoc}] = self.class.interpret_type(v, api_creds)
93
+ # else
94
+ # @attribs[:#{assoc}] = v
95
+ # end
96
+ # end
97
+ # alias :#{assoc}= :#{assoc}_attributes=
98
+ # M3
99
+ # end
100
+
57
101
  def belongs_to(assoc, klass=nil)
58
102
  assoc = assoc.to_s
59
103
  klass ||= "#{module_name}::#{assoc.camelize}"
@@ -61,6 +105,7 @@ module NCore
61
105
  attr :#{assoc}_id
62
106
  def #{assoc}(params={})
63
107
  return nil unless #{assoc}_id
108
+ # @attribs[:#{assoc}] ||= #{klass}.find(#{assoc}_id, params, api_creds)
64
109
  if params.empty?
65
110
  # only cache unfiltered, default api call
66
111
  @attribs[:#{assoc}] ||= #{klass}.find(#{assoc}_id, {}, api_creds)
@@ -28,7 +28,7 @@ module NCore
28
28
  end
29
29
 
30
30
  def url
31
- "#{self.class.url}/#{CGI.escape id||'-'}"
31
+ "#{self.class.url}/#{CGI.escape((id||'-').to_s)}"
32
32
  end
33
33
 
34
34
  end
@@ -200,7 +200,9 @@ module NCore
200
200
  raise parent::AccessDenied, "Access denied; check your API credentials and permissions."
201
201
  when 404
202
202
  raise parent::RecordNotFound
203
- when 422
203
+ # when 409
204
+ # raise parent::Conflict
205
+ when 422, 409 # todo: is this really universally true (check both AR + PS)
204
206
  # pass through
205
207
  when 429
206
208
  raise parent::RateLimited
@@ -48,8 +48,13 @@ module NCore
48
48
 
49
49
  mattr_accessor :logger
50
50
  self.logger = Logger.new(STDOUT)
51
+ # self.logger.level = Logger::DEBUG
51
52
  end
52
53
 
54
+ # def credentials=(v)
55
+ # super v.with_indifferent_access
56
+ # end
57
+
53
58
  end
54
59
 
55
60
  end
@@ -3,10 +3,17 @@ module NCore
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def delete(id, params={}, api_creds=nil)
6
+ def delete!(id, params={}, api_creds=nil)
7
7
  obj = new({id: id}, api_creds)
8
8
  obj.delete(params) || raise(parent::RecordInvalid, obj)
9
9
  end
10
+
11
+ # always returns a new object; check .errors? or .valid? to see how it went
12
+ def delete(id, params={}, api_creds=nil)
13
+ obj = new({id: id}, api_creds)
14
+ obj.delete(params)
15
+ obj
16
+ end
10
17
  end
11
18
 
12
19
  def delete(params={})
@@ -8,9 +8,11 @@ module NCore
8
8
  obj.save!(attribs)
9
9
  end
10
10
 
11
+ # always returns a new object; check .errors? or .valid? to see how it went
11
12
  def update(id, attribs, api_creds=nil)
12
13
  obj = new({id: id}, api_creds)
13
14
  obj.save(attribs)
15
+ obj
14
16
  end
15
17
  end
16
18
 
@@ -1,3 +1,3 @@
1
1
  module NCore
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -7,10 +7,12 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "ncore"
8
8
  spec.version = NCore::VERSION
9
9
  spec.authors = ["thomas morgan"]
10
- spec.email = ["tm@notioneer.com"]
10
+ spec.email = ["hello@notioneer.com"]
11
11
  spec.description = %q{NCore - Ruby gem useful for building REST API clients}
12
12
  spec.summary = %q{NCore - Gem for building REST API clients}
13
+ # spec.homepage = "https://github.com/notioneer/ncore-ruby"
13
14
  spec.homepage = 'http://notioneer.com/'
15
+ # spec.homepage = 'https://authrocket.com/'
14
16
  spec.license = "MIT"
15
17
 
16
18
  spec.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,99 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: excon
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.32'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0.32'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: multi_json
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.7'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ~>
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.7'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ~>
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.3'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ~>
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.3'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  description: NCore - Ruby gem useful for building REST API clients
90
90
  email:
91
- - tm@notioneer.com
91
+ - hello@notioneer.com
92
92
  executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - .gitignore
96
+ - ".gitignore"
97
97
  - Gemfile
98
98
  - LICENSE
99
99
  - README.md
@@ -141,17 +141,17 @@ require_paths:
141
141
  - lib
142
142
  required_ruby_version: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - '>='
149
+ - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.0.6
154
+ rubygems_version: 2.4.3
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: NCore - Gem for building REST API clients