Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Spire

Spire is a Ruby wrapper around the [Spire Systems API](http://www.spiresystems.com/).

This gem was inspired by [ruby-trello](https://github.com/jeremytregunna/ruby-trello).
Expand All @@ -22,13 +23,29 @@ gem 'spire', git: "https://github.com/bitesite/spire-ruby", tag: "v2.5.0"

And then execute:

$ bundle
```shell
$ bundle
```

## Usage

First you will need to configure spire. This is a global configuration. Thus it will be applied anywhere you use spire within
your application.

### Rails

There are 2 options to configure your rails project to use this gem.

**Automated Rails Generator**

Run the following command in your projects root folder.

```shell
$ rails generate spire:install
```

**Manual**

If you are using spire within a Rails application, you could put the following config in an initializer.

```ruby
Expand All @@ -41,97 +58,117 @@ end
```

### Items

Below are a few usage examples. For other uses, please refer to `lib/item.rb`.

Will retrieve one item from Spire

```ruby
Spire::Item.find(itemId)
```

Will search Spire for an item that matches the given query

```ruby
Spire::Item.search('GF-1234')
```

Will retrieve many Items based on a filter from Spire

```ruby
Spire::Item.filter('{"partNo":"ABCD-0001", "whse":"00"}')
```

Will create a new item on Spire

```ruby
Spire::Item.create(options)
```

Will delete an item from Spire

```ruby
Spire::Item.find(itemId).delete
```

Updates item description on Spire

```ruby
item = Spire::Item.find(71)
item.description = 'This is a new description'
item.save
```

### UPCs

Below are a few usage examples. For other uses, please refer to `lib/upc.rb`.

Will retrieve many UPCs based on a filter from Spire

```ruby
Spire::Upc.filter('{"partNo":"ABCD-0001", "whse":"00"}')
```

Will retrieve one UPC from Spire

```ruby
Spire::Upc.find(upcId)
```

Will create a new UPC on Spire

```ruby
Spire::Upc.create(upc: "12345678901", uomCode: "EA", inventory: {id: 1})
```

Will delete a UPC from Spire

```ruby
Spire::Upc.find(upcId).delete
```

Updates a UPC on Spire

```ruby
upc = Spire::Upc.find(1)
upc.upc = '12345678902'
upc.save
```

### Customers

Below are a few usage examples. For other uses, please refer to `lib/customer.rb`.

Will retrieve one customer from Spire

```ruby
Spire::Customer.find(customerId)
```

Will search Spire for a customer that matches the given query

```ruby
Spire::Customer.search('[email protected]')
```

### Orders

The syntax for orders is very similar to items. For additional information please refer to `lib/order.rb`.

Will retrieve one order from Spire

```ruby
Spire::Order.find(orderId)
```

Will search Spire for any order that match the given query

```ruby
Spire::Order.search('[email protected]')
```

Will create order in Spire

```ruby
Spire::Order.create({
'customer' => {'id': 'customer id'},
Expand Down Expand Up @@ -167,12 +204,15 @@ Spire::Order.create({
'freight': '14'
})
```
*Above is the minimum param to create an order in Spire*

_Above is the minimum param to create an order in Spire_

### Vendors

The syntax for vendors is very similar to items. For additional information please refer to `lib/vendor.rb`.

Will retrieve one vendor from Spire

```ruby
Spire::Vendor.find(vendorId)
```
Expand All @@ -193,23 +233,23 @@ To install this gem onto your local machine, run `bundle exec rake install`.
4. ~~Build the gem `gem build spire.gemspec`~~
5. ~~Publish to BiteSite's RubyGems account `gem push spire-2.4.1.gem`~~

After trying to publish to rubygems.org, we realized we had a name conflict. If we changed the name of the gem,
After trying to publish to rubygems.org, we realized we had a name conflict. If we changed the name of the gem,
that would also affect the code that requires the top-level package. Until we're willing to release a Major version
upgrade with breaking changes, we'll just have to publish via GitHub.
upgrade with breaking changes, we'll just have to publish via GitHub.

Until then, when we're ready to release a new version:

1. On master, `git checkout master`
2. Make sure you have the latest changes `git pull`
2. Update `spire/version.rb` with a new version number following Semantic Versioning Rules.
3. Commit the change `git add .` and `git commit -m "Updated version number for release."`
4. Push changes `git push origin master`
5. Tag the commit `git tag 'vX.X.X'`
6. Push tags `git push origin --tags`
3. Update `spire/version.rb` with a new version number following Semantic Versioning Rules.
4. Commit the change `git add .` and `git commit -m "Updated version number for release."`
5. Push changes `git push origin master`
6. Tag the commit `git tag 'vX.X.X'`
7. Push tags `git push origin --tags`

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bitesite/spire.
Bug reports and pull requests are welcome on GitHub at https://github.com/bitesite/spire-ruby.

We do not currently support the entire [Spire](http://www.spiresystems.com/) api.
Any pull requests adding CRUD resources to this gem are appreciated.
Expand Down
43 changes: 43 additions & 0 deletions lib/generators/spire/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Spire
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caseyli I think this would warrant a version update. Not sure if its x, y, or z in the X.Y.Z version number.

module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__)

desc "Creates a spire initializer."

def setup_initializer
template "spire.rb", "config/initializers/spire.rb"

if yes?("\nAre you using the dotenv-rails gem to store your environment variables?")
gsub_file "config/initializers/spire.rb", /(config\.company.+)/, "config.company = ENV['SPIRE_COMPANY']"
gsub_file "config/initializers/spire.rb", /(config\.username.+)/, "config.username = ENV['SPIRE_USERNAME']"
gsub_file "config/initializers/spire.rb", /(config\.password.+)/, "config.password = ENV['SPIRE_PASSWORD']"
gsub_file "config/initializers/spire.rb", /(config\.host.+)/, "config.host = ENV['SPIRE_HOST']"
gsub_file "config/initializers/spire.rb", /(config\.port.+)/, "config.port = ENV['SPIRE_PORT']"

if yes?("\nDo you have the Spire configuration variables?")
spire_company = ask("Spire Company:")
spire_host = ask("Spire Host:")
spire_port = ask("Spire Port:")
spire_username = ask("Spire Username:")
spire_password = ask("Spire Password:")

spire_env_vars = <<~EOF
SPIRE_COMPANY=#{spire_company}
SPIRE_HOST=#{spire_host}
SPIRE_PORT=#{spire_port}
SPIRE_USERNAME=#{spire_username}
SPIRE_PASSWORD=#{spire_password}
EOF

if File.file?(".env")
inject_into_file ".env", spire_env_vars
else
create_file ".env", spire_env_vars
end
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/generators/templates/spire.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Spire.configure do |config|
config.company = "company name"
config.username = "username" # Username of a user account within "company name"
config.password = "xxxxxxxx" # Password of that user
config.host = "example.com" # Location of your Spire server
config.port = "123" # Port of your Spire server
end