qbo_api 1.0.3 → 1.1.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: 401db6738cc3696410262b1a5fe6d175cc9a82a4
4
- data.tar.gz: ef8a65ab5442aee5d1cc8b7cce3f4532ce453a91
3
+ metadata.gz: 9705a6a9fde66e76546b9203e846d505dd5d3f15
4
+ data.tar.gz: 171efdaf99db8369c5a7abe900ee2be306600a10
5
5
  SHA512:
6
- metadata.gz: f1e1b50e26f41019def51c970a44760fa1b55fb85f8946c307f60fc5f54f6f3ffb92b33ccc80085a27d91da5613f99e3e773bc8bb1c0971c5c0fda1c0804483d
7
- data.tar.gz: 4f4a6b436ffb17753ca83b08246441cf7649577bf830f02953635e7b0530d19c76fb802fdfd165dc553b30fab83fee4b0f84b4ef0dcb53de376a1b76c3b34a70
6
+ metadata.gz: c4ce0818cb0ef23707b903d765d092b6e2a784d1e3cfe2ac570cbe4be31d25a9bf91dc5dfde76281b62279543f31b650c67dd25591f0a1c8c991cf5ea2910da6
7
+ data.tar.gz: 8a9007b00ec9464125a5851c97a5f1754cc74472ff2292a0fbc7a505140b89693958632e2757f618988aa25900a7608df6d29d35a2f42f5cc251e38d98217bdc
data/lib/qbo_api.rb CHANGED
@@ -59,24 +59,22 @@ class QboApi
59
59
  end
60
60
 
61
61
  def get(entity, id)
62
- path = "#{realm_id}/#{entity.to_s}/#{id}"
62
+ path = "#{entity_path(entity)}/#{id}"
63
63
  request(:get, entity: entity, path: path)
64
64
  end
65
65
 
66
66
  def create(entity, payload:)
67
- path = "#{realm_id}/#{entity}"
68
- request(:post, entity: entity, path: path, payload: payload)
67
+ request(:post, entity: entity, path: entity_path(entity), payload: payload)
69
68
  end
70
69
 
71
70
  def update(entity, id:, payload:)
72
- path = "#{realm_id}/#{entity}"
73
71
  payload.merge!(set_update(entity, id))
74
- request(:post, entity: entity, path: path, payload: payload)
72
+ request(:post, entity: entity, path: entity_path(entity), payload: payload)
75
73
  end
76
74
 
77
75
  def delete(entity, id:)
78
76
  raise QboApi::NotImplementedError unless is_transaction_entity?(entity)
79
- path = "#{realm_id}/#{entity}?operation=delete"
77
+ path = "#{entity_path(entity)}?operation=delete"
80
78
  payload = set_update(entity, id)
81
79
  request(:post, entity: entity, path: path, payload: payload)
82
80
  end
@@ -13,6 +13,10 @@ class QboApi
13
13
  end
14
14
  end
15
15
 
16
+ def entity_path(entity)
17
+ "#{realm_id}/#{singular(entity).downcase}"
18
+ end
19
+
16
20
  def snake_to_camel(sym)
17
21
  sym.to_s.split('_').collect(&:capitalize).join
18
22
  end
@@ -78,9 +82,19 @@ class QboApi
78
82
 
79
83
  def extract_entity_from_query(query, to_sym: false)
80
84
  if m = query.match(/from\s+(\w+)\s/i)
81
- (to_sym ? m[1].downcase.to_sym : m[1].capitalize) if m[1]
85
+ (to_sym ? underscore(m[1]).to_sym : m[1]) if m[1]
82
86
  end
83
87
  end
84
88
 
89
+ private
90
+
91
+ def underscore(entity)
92
+ entity.gsub(/::/, '/')
93
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
94
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
95
+ .tr("-", "_")
96
+ .downcase
97
+ end
98
+
85
99
  end
86
100
  end
@@ -1,3 +1,3 @@
1
1
  class QboApi
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler