elmas 0.2.0 → 1.0.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 +4 -4
- data/README.md +24 -1
- data/lib/elmas/exception.rb +4 -8
- data/lib/elmas/oauth.rb +6 -2
- data/lib/elmas/parser.rb +14 -8
- data/lib/elmas/resources/account.rb +1 -1
- data/lib/elmas/resources/project.rb +34 -0
- data/lib/elmas/resources/time_transaction.rb +28 -0
- data/lib/elmas/response.rb +4 -5
- data/lib/elmas/sanitizer.rb +1 -1
- data/lib/elmas/uri.rb +6 -1
- data/lib/elmas/version.rb +2 -2
- data/lib/elmas.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31ec8dd25ceb6a01b7d07b240c16b8d33616cb33
|
4
|
+
data.tar.gz: 6877c0e58d2ba5c5ff77eba97a599e5ecf220ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c9aecd1f8e78b21621aec927ea74ece5e3d2e55780e5b650eb4e2278a960a543d5a83c18148117156ee07e4ab717ba48708d299db33c61d543d7e1220e6e9cc
|
7
|
+
data.tar.gz: e7047f922618c9efaf666e6ad2dd46a80381349c0fd9c038d25cfd462fdf076e736fea865d5abfac2684f60f5ebd44353ce2acc0ee736dc9eed6b7a0105ab7ee
|
data/README.md
CHANGED
@@ -155,10 +155,33 @@ contact.find_all(select: [:last_name, :first_name])
|
|
155
155
|
To create a new contact
|
156
156
|
|
157
157
|
```ruby
|
158
|
-
contact = Elmas::Contact.new(first_name: "Karel", last_name: "Appel" )
|
158
|
+
contact = Elmas::Contact.new(first_name: "Karel", last_name: "Appel", account: "8d87c8c5-f1c6-495c-b6af-d5ba396873b5" )
|
159
159
|
contact.save
|
160
160
|
```
|
161
161
|
|
162
|
+
### Projects and Time Tracking
|
163
|
+
|
164
|
+
Project Types:
|
165
|
+
|
166
|
+
- :type=>2, :type_description=>"Fixed price"
|
167
|
+
- :type=>3, :type_description=>"Time and Material"
|
168
|
+
- :type=>4, :type_description=>"Non billable"
|
169
|
+
- :type=>5, :type_description=>"Prepaid"
|
170
|
+
|
171
|
+
To create a new project
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
project = Elmas::Project.new(code: "PROJ902343", description: "Great project", account: "8d87c8c5-f1c6-495c-b6af-d5ba396873b5", type: 2 )
|
175
|
+
project.save
|
176
|
+
```
|
177
|
+
|
178
|
+
To submit a new time transaction
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
hours = Elmas::TimeTransaction.new(account: "8d87c8c5-f1c6-495c-b6af-d5ba396873b5", item: "eb73942a-53c0-4ee9-bbb2-6d985814a1b1", quantity: 3.0, notes: "")
|
182
|
+
hours.save
|
183
|
+
```
|
184
|
+
|
162
185
|
### SalesInvoice flow
|
163
186
|
SalesInvoices have a relationship with SalesInvoiceLines. A SalesInvoice has many
|
164
187
|
SalesInvoiceLines and a SalesInvoiceLine belongs to a SalesInvoice. To create a
|
data/lib/elmas/exception.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
module Elmas
|
2
2
|
class BadRequestException < Exception
|
3
|
-
def initialize(
|
3
|
+
def initialize(response, parsed)
|
4
|
+
@response = response
|
5
|
+
@parsed = parsed
|
4
6
|
super(message)
|
5
|
-
@object = object
|
6
7
|
end
|
7
8
|
|
8
9
|
def message
|
9
|
-
|
10
|
-
when 500
|
11
|
-
"Server error"
|
12
|
-
else
|
13
|
-
"Something went wrong"
|
14
|
-
end
|
10
|
+
"code #{@response.status}: #{@parsed.error_message}"
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
data/lib/elmas/oauth.rb
CHANGED
@@ -19,9 +19,13 @@ module Elmas
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def authorized?
|
22
|
-
response = get("/Current/Me", no_division: true)
|
23
|
-
!response.unauthorized?
|
24
22
|
# Do a test call, return false if 401 or any error code
|
23
|
+
begin
|
24
|
+
response = get("/Current/Me", no_division: true)
|
25
|
+
rescue BadRequestException => e
|
26
|
+
Elmas.error "Not yet authorized"
|
27
|
+
return false
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
def authorize_division
|
data/lib/elmas/parser.rb
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
module Elmas
|
2
2
|
class Parser
|
3
|
+
attr_accessor :parsed_json
|
4
|
+
|
3
5
|
def initialize(json)
|
4
|
-
@
|
6
|
+
@parsed_json = JSON.parse(json)
|
5
7
|
rescue JSON::ParserError => e
|
6
|
-
Elmas.error
|
7
|
-
|
8
|
-
|
8
|
+
Elmas.error 'There was an error parsing the response'
|
9
|
+
Elmas.error "#{e.class}: #{e.message}"
|
10
|
+
@error_message = "#{e.class}: #{e.message}"
|
9
11
|
end
|
10
12
|
|
11
13
|
def results
|
12
|
-
|
14
|
+
result['results'] if result && result['results']
|
13
15
|
end
|
14
16
|
|
15
17
|
def metadata
|
16
|
-
|
18
|
+
result['__metadata'] if result && result['__metadata']
|
17
19
|
end
|
18
20
|
|
19
21
|
def result
|
20
|
-
|
22
|
+
parsed_json['d']
|
21
23
|
end
|
22
24
|
|
23
25
|
def error_message
|
24
|
-
@error_message ||=
|
26
|
+
@error_message ||= begin
|
27
|
+
if parsed_json['error']
|
28
|
+
parsed_json['error']['message']['value']
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
def first_result
|
@@ -11,7 +11,7 @@ module Elmas
|
|
11
11
|
[:name]
|
12
12
|
end
|
13
13
|
|
14
|
-
# https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?
|
14
|
+
# https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=CRMAccounts
|
15
15
|
def other_attributes # rubocop:disable Metrics/MethodLength
|
16
16
|
[
|
17
17
|
:accountant, :account_manager, :activity_sector,
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Elmas
|
2
|
+
class Project
|
3
|
+
include Elmas::Resource
|
4
|
+
|
5
|
+
def base_path
|
6
|
+
"project/Projects"
|
7
|
+
end
|
8
|
+
|
9
|
+
def mandatory_attributes
|
10
|
+
[:account, :description, :code, :type]
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=ProjectProjects
|
14
|
+
def other_attributes # rubocop:disable Metrics/MethodLength
|
15
|
+
[
|
16
|
+
:account, :account_code, :AccountContact, :account_name,
|
17
|
+
:allow_additional_invoicing, :block_entry, :block_rebilling,
|
18
|
+
:budgeted_amount, :budgeted_costs, :budgeted_hours_per_hour_type,
|
19
|
+
:BudgetedRevenue, :BudgetType, :BudgetTypeDescription, :clasification,
|
20
|
+
:classification_description, :code, :costs_amount_fc, :created,
|
21
|
+
:creator, :creator_full_name, :customer_p_onumber, :description,
|
22
|
+
:division, :division_name, :end_date, :fixed_price_item,
|
23
|
+
:fixed_price_item_description, :invoice_as_quoted, :invoice_terms,
|
24
|
+
:manager, :manager_fullname, :markup_percentage, :modified, :modifier,
|
25
|
+
:modifier_full_name, :notes, :prepaid_item, :prepaid_item_description,
|
26
|
+
:prepaid_type, :prepaid_type_description,
|
27
|
+
:project_restriction_employees, :project_restriction_items,
|
28
|
+
:project_restriction_rebillings, :sales_time_quantity,
|
29
|
+
:source_quotation, :start_date, :time_quantity_to_alert, :type,
|
30
|
+
:type_description, :use_billing_milestones
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Elmas
|
2
|
+
class TimeTransaction
|
3
|
+
include Elmas::Resource
|
4
|
+
|
5
|
+
def base_path
|
6
|
+
"project/TimeTransactions"
|
7
|
+
end
|
8
|
+
|
9
|
+
def mandatory_attributes
|
10
|
+
[:account, :item, :quantity]
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=ProjectTimeTransactions
|
14
|
+
def other_attributes
|
15
|
+
[
|
16
|
+
:account, :account_name, :activity, :activity_description, :amount, :amount_fc,
|
17
|
+
:attachment, :created, :creator, :creator_full_name, :currency, :date,
|
18
|
+
:division, :division_description, :employee, :end_time, :entry_number,
|
19
|
+
:error_text, :hour_status, :item, :item_description, :item_divisable,
|
20
|
+
:modified, :modifier, :modifier_full_name, :notes, :price, :price_fc, :project,
|
21
|
+
:project_account, :project_account_code, :project_account_name,
|
22
|
+
:project_description, :quantity, :start_time, :subscription,
|
23
|
+
:subscription_account, :subscription_account_code, :subscription_account_name,
|
24
|
+
:subscription_description, :subscription_number, :type
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/elmas/response.rb
CHANGED
@@ -7,7 +7,10 @@ module Elmas
|
|
7
7
|
|
8
8
|
def initialize(response)
|
9
9
|
@response = response
|
10
|
-
|
10
|
+
if fail?
|
11
|
+
log_error
|
12
|
+
raise BadRequestException.new(@response, parsed)
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
def success?
|
@@ -68,10 +71,6 @@ module Elmas
|
|
68
71
|
Elmas.error(message)
|
69
72
|
end
|
70
73
|
|
71
|
-
def unauthorized?
|
72
|
-
UNAUTHORIZED_CODES.include? status
|
73
|
-
end
|
74
|
-
|
75
74
|
SUCCESS_CODES = [
|
76
75
|
201, 202, 203, 204, 301, 302, 303, 304
|
77
76
|
]
|
data/lib/elmas/sanitizer.rb
CHANGED
data/lib/elmas/uri.rb
CHANGED
@@ -27,7 +27,12 @@ module Elmas
|
|
27
27
|
if attribute == :id
|
28
28
|
return id_filter
|
29
29
|
else
|
30
|
-
|
30
|
+
if @attributes[attribute].is_a?(Fixnum)
|
31
|
+
value = @attributes[attribute]
|
32
|
+
else
|
33
|
+
value = "'#{@attributes[attribute]}'"
|
34
|
+
end
|
35
|
+
return ["$filter", "#{Utils.camelize(attribute)} eq #{value}"]
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
data/lib/elmas/version.rb
CHANGED
data/lib/elmas.rb
CHANGED
@@ -22,6 +22,8 @@ require "elmas/resources/sales_entry"
|
|
22
22
|
require "elmas/resources/sales_entry_line"
|
23
23
|
require "elmas/resources/sales_order"
|
24
24
|
require "elmas/resources/sales_order_line"
|
25
|
+
require "elmas/resources/project"
|
26
|
+
require "elmas/resources/time_transaction"
|
25
27
|
require "elmas/resources/purchase_entry"
|
26
28
|
require "elmas/resources/purchase_entry_line"
|
27
29
|
require "elmas/resources/costunit"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elmas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marthyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -256,6 +256,7 @@ files:
|
|
256
256
|
- lib/elmas/resources/item_group.rb
|
257
257
|
- lib/elmas/resources/journal.rb
|
258
258
|
- lib/elmas/resources/mailbox.rb
|
259
|
+
- lib/elmas/resources/project.rb
|
259
260
|
- lib/elmas/resources/purchase_entry.rb
|
260
261
|
- lib/elmas/resources/purchase_entry_line.rb
|
261
262
|
- lib/elmas/resources/sales_entry.rb
|
@@ -265,6 +266,7 @@ files:
|
|
265
266
|
- lib/elmas/resources/sales_order.rb
|
266
267
|
- lib/elmas/resources/sales_order_line.rb
|
267
268
|
- lib/elmas/resources/shared_sales_attributes.rb
|
269
|
+
- lib/elmas/resources/time_transaction.rb
|
268
270
|
- lib/elmas/resources/transaction.rb
|
269
271
|
- lib/elmas/resources/transaction_line.rb
|
270
272
|
- lib/elmas/resources/vat_code.rb
|