finale 0.1.2 → 0.1.3

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: 39d6ca5d2a4c1870b4848e13f98b758537ecc1eb
4
- data.tar.gz: a93d9394f35f9d8423c38690f858cd97f69d691f
3
+ metadata.gz: 9c2549196c2c78881f1fdc2b48e0da4552a7821f
4
+ data.tar.gz: a90de795f5c19f9de201081657f8b8bf77009fbb
5
5
  SHA512:
6
- metadata.gz: b2238fa55f6c4c94a70a20d0fa8d2ea59c17c83955c9774c1c66dc28eb8095bb2d4dc46ecc89fb0bfc14e9fa03a7f981ffad9bda906dfdc31e662d4af395c0ec
7
- data.tar.gz: 10f578be0f6f609a1bd037a83b04ceed1b28438f02e07cc6e89b35eed34d4e395172686c8484f4b95a2c33d644d82dd48e5816136f05f1fd823d4dda4fc8301b
6
+ metadata.gz: 3431646ac3855e4b8e48f19695d8e9b14a9e1733cc58f5428e643b741ca0d5da63af40765d4a7755184c39aeac1f256cda238f1c0349b3a6ce3c2f8466dc4b82
7
+ data.tar.gz: 452f6d2b5ade9bbb2f3751b40f8e6cfe362c03f7c1ea47959293d25128751dbd76bf7a340e9870a20816f3c8a482a8546fde72ecf15e03ef7fdd40bf23dcbd7d
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Version ](https://img.shields.io/gem/v/finale.svg?maxAge=2592000)](https://rubygems.org/gems/finale)
2
+ [![Build Status ](https://travis-ci.org/popp0102/finale.svg)](https://travis-ci.org/popp0102/finale)
3
+ [![Code Climate ](https://api.codeclimate.com/v1/badges/7c7d7c83bde6c288f5e8/maintainability)](https://codeclimate.com/github/popp0102/finale/maintainability)
4
+ [![Test Coverage](https://codeclimate.com/github/popp0102/finale/badges/coverage.svg)](https://codeclimate.com/github/popp0102/finale/coverage)
5
+
1
6
  # Finale
2
7
 
3
8
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/finale`. To experiment with that code, run `bin/console` for an interactive prompt.
@@ -1,4 +1,7 @@
1
1
  require "rest-client"
2
+ require "json"
3
+ require "base64"
4
+ require "active_support/all"
2
5
 
3
6
  require "finale/version"
4
7
  require "finale/errors"
@@ -10,10 +13,10 @@ module Finale
10
13
  MAX_REQUESTS = 100 # Finale API Usage: 'https://support.finaleinventory.com/hc/en-us/articles/115007830648-Getting-Started'
11
14
  BASE_URL = 'https://app.finaleinventory.com'
12
15
 
13
- def initialize(company)
16
+ def initialize(account)
14
17
  @cookies = nil
15
18
  @request_count = 0
16
- @company = company
19
+ @account = account
17
20
  @login_url = construct_url(:auth)
18
21
  @order_url = construct_url(:order)
19
22
  @shipment_url = construct_url(:shipment)
@@ -28,19 +31,20 @@ module Finale
28
31
  request(verb: :LOGIN, payload: payload)
29
32
  end
30
33
 
31
- def get_order_ids
32
- body = request(verb: :GET, url: @order_url)
33
- order_ids = body[:orderId]
34
- order_ids.map(&:to_i).sort.uniq
35
- end
36
-
37
34
  def get_order(id)
38
35
  response = request(verb: :GET, url: "#{@order_url}/#{id}")
39
36
  Order.new(response)
40
37
  end
41
38
 
39
+ def get_orders(filter: nil)
40
+ resp_orders = request(verb: :GET, url: @order_url, filter: filter )
41
+ rows = column_major_to_row_major(resp_orders)
42
+ orders = rows.map { |r| Order.new(r) }
43
+ orders
44
+ end
45
+
42
46
  def get_shipments(order)
43
- order.shipment_urls.map do |suffix_url|
47
+ order.shipmentUrlList.map do |suffix_url|
44
48
  url = "#{BASE_URL}#{suffix_url}"
45
49
  response = request(verb: :GET, url: url)
46
50
  Shipment.new(response)
@@ -49,11 +53,24 @@ module Finale
49
53
 
50
54
  private
51
55
 
56
+ def column_major_to_row_major(column_major)
57
+ row_major = []
58
+ keys = column_major.keys
59
+ values = column_major.values || [[]]
60
+ num_cols = values.count == 0 ? 0 : values.first.count
61
+ num_cols.times do
62
+ rowvals = keys.map { |key| column_major[key].shift }
63
+ row = Hash[keys.zip(rowvals)]
64
+ row_major << row
65
+ end
66
+ row_major
67
+ end
68
+
52
69
  def construct_url(resource)
53
- "#{BASE_URL}/#{@company}/api/#{resource}"
70
+ "#{BASE_URL}/#{@account}/api/#{resource}"
54
71
  end
55
72
 
56
- def request(verb: nil, url: nil, payload: nil)
73
+ def request(verb: nil, url: nil, payload: nil, filter: nil)
57
74
  raise MaxRequests.new(MAX_REQUESTS) if @request_count >= MAX_REQUESTS
58
75
  raise NotLoggedIn.new(verb: verb, url: url) unless verb == :LOGIN || !@cookies.nil?
59
76
 
@@ -62,7 +79,14 @@ module Finale
62
79
  response = RestClient.post(@login_url, payload)
63
80
  @cookies = response.cookies
64
81
  when :GET
65
- response = RestClient.get(url, cookies: @cookies)
82
+ params = {}
83
+
84
+ if filter.present?
85
+ encoded_filter = Base64.encode64(filter.to_json)
86
+ params.merge!(filter: encoded_filter)
87
+ end
88
+
89
+ response = RestClient.get(url, cookies: @cookies, params: params)
66
90
  when :POST
67
91
  response = RestClient.post(url, cookies: @cookies)
68
92
  end
@@ -1,12 +1,7 @@
1
- module Finale
2
- class Order
3
- attr_reader :id, :shipment_urls, :source
1
+ require 'ostruct'
4
2
 
5
- def initialize(order_response)
6
- @id = order_response[:orderId]&.to_i
7
- @shipment_urls = order_response[:shipmentUrlList]
8
- @source = order_response[:saleSourceId]
9
- end
3
+ module Finale
4
+ class Order < OpenStruct
10
5
  end
11
6
  end
12
7
 
@@ -1,11 +1,5 @@
1
1
  module Finale
2
- class Shipment
3
- attr_reader :id, :item_list
4
-
5
- def initialize(shipment_response)
6
- @id = shipment_response[:shipmentId]&.to_i
7
- @item_list = shipment_response[:shipmentItemList]
8
- end
2
+ class Shipment < OpenStruct
9
3
  end
10
4
  end
11
5
 
@@ -1,3 +1,3 @@
1
1
  module Finale
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finale
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
- - popp0102
7
+ - Jason Poppler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-22 00:00:00.000000000 Z
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rest-client
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,24 +136,28 @@ dependencies:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
138
  version: '4.10'
111
- description: A client to interact with the Finale Inventory System.
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.16'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.16'
153
+ description:
112
154
  email:
113
155
  - popp0102@getnotion.com
114
156
  executables: []
115
157
  extensions: []
116
158
  extra_rdoc_files: []
117
159
  files:
118
- - ".gitignore"
119
- - ".rspec"
120
- - ".travis.yml"
121
- - CODE_OF_CONDUCT.md
122
- - Gemfile
123
- - LICENSE.txt
124
160
  - README.md
125
- - Rakefile
126
- - bin/console
127
- - bin/setup
128
- - finale.gemspec
129
161
  - lib/finale.rb
130
162
  - lib/finale/errors.rb
131
163
  - lib/finale/order.rb
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
- *.swp
11
- *.swo
12
- *.swn
13
-
14
- # rspec failure tracking
15
- .rspec_status
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.4.4
7
- before_install: gem install bundler -v 1.16.3
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at jason@getnotion.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in finale.gemspec
6
- gemspec
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2018 jpoppler
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "finale"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,43 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "finale/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "finale"
8
- spec.version = Finale::VERSION
9
- spec.authors = ["popp0102"]
10
- spec.email = ["popp0102@getnotion.com"]
11
-
12
- spec.summary = 'A client to interact with the Finale Inventory System.'
13
- spec.description = 'A client to interact with the Finale Inventory System.'
14
- spec.homepage = "https://github.com/popp0102/finale"
15
- spec.license = "MIT"
16
-
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
24
- end
25
-
26
- # Specify which files should be added to the gem when it is released.
27
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
- end
31
- spec.bindir = "exe"
32
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
34
-
35
- spec.add_runtime_dependency "rest-client", "~> 2.0"
36
-
37
- spec.add_development_dependency "bundler", "~> 1.16"
38
- spec.add_development_dependency "webmock", "~> 3.4"
39
- spec.add_development_dependency "rake", "~> 10.0"
40
- spec.add_development_dependency "rspec", "~> 3.0"
41
- spec.add_development_dependency 'pry-byebug', '~> 3'
42
- spec.add_development_dependency "factory_bot", "~> 4.10"
43
- end