oshpark 0.0.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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +97 -0
- data/Guardfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +7 -0
- data/bin/oshpark +44 -0
- data/lib/oshpark.rb +31 -0
- data/lib/oshpark/address.rb +46 -0
- data/lib/oshpark/client.rb +222 -0
- data/lib/oshpark/connection.rb +85 -0
- data/lib/oshpark/dimensionable.rb +27 -0
- data/lib/oshpark/ext.rb +122 -0
- data/lib/oshpark/image.rb +9 -0
- data/lib/oshpark/import.rb +38 -0
- data/lib/oshpark/layer.rb +13 -0
- data/lib/oshpark/model.rb +110 -0
- data/lib/oshpark/order.rb +72 -0
- data/lib/oshpark/order_option.rb +9 -0
- data/lib/oshpark/panel.rb +28 -0
- data/lib/oshpark/project.rb +50 -0
- data/lib/oshpark/rubymotion.rb +9 -0
- data/lib/oshpark/shipping_rate.rb +11 -0
- data/lib/oshpark/token.rb +24 -0
- data/lib/oshpark/upload.rb +37 -0
- data/lib/oshpark/user.rb +9 -0
- data/lib/oshpark/version.rb +3 -0
- data/oshpark.gemspec +29 -0
- data/spec/lib/oshpark/address_spec.rb +13 -0
- data/spec/lib/oshpark/client_spec.rb +139 -0
- data/spec/lib/oshpark/image_spec.rb +9 -0
- data/spec/lib/oshpark/import_spec.rb +19 -0
- data/spec/lib/oshpark/layer_spec.rb +14 -0
- data/spec/lib/oshpark/model_spec.rb +41 -0
- data/spec/lib/oshpark/order_spec.rb +87 -0
- data/spec/lib/oshpark/panel_spec.rb +17 -0
- data/spec/lib/oshpark/project_spec.rb +9 -0
- data/spec/lib/oshpark/upload_spec.rb +18 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/http_client.rb +24 -0
- metadata +282 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
module Oshpark
|
2
|
+
class Panel
|
3
|
+
def self.attrs
|
4
|
+
%w| pcb_layers scheduled_order_time expected_receive_time
|
5
|
+
id ordered_at received_at state service total_orders
|
6
|
+
total_boards board_area_in_square_mils |
|
7
|
+
end
|
8
|
+
|
9
|
+
include Model
|
10
|
+
|
11
|
+
def scheduled_order_time
|
12
|
+
time_from @scheduled_order_time if @scheduled_order_time
|
13
|
+
end
|
14
|
+
|
15
|
+
def expected_receive_time
|
16
|
+
time_from @expected_receive_time if @expected_receive_time
|
17
|
+
end
|
18
|
+
|
19
|
+
def ordered_at
|
20
|
+
time_from @ordered_at if @ordered_at
|
21
|
+
end
|
22
|
+
|
23
|
+
def received_at
|
24
|
+
time_from @received_at if @received_at
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Oshpark
|
2
|
+
class Project
|
3
|
+
def self.attrs
|
4
|
+
%w| id design_file_url name description top_image bottom_image width_in_mils height_in_mils pcb_layers state layers order_options is_shared |
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.write_attrs
|
8
|
+
%w| name description |
|
9
|
+
end
|
10
|
+
|
11
|
+
include Model
|
12
|
+
include Dimensionable
|
13
|
+
|
14
|
+
alias shared? is_shared
|
15
|
+
|
16
|
+
def top_image
|
17
|
+
Image.from_json @top_image
|
18
|
+
end
|
19
|
+
|
20
|
+
def bottom_image
|
21
|
+
Image.from_json @bottom_image
|
22
|
+
end
|
23
|
+
|
24
|
+
def layers
|
25
|
+
@layers.map do |json|
|
26
|
+
Layer.from_json json
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def order_options
|
31
|
+
@order_options.map do |json|
|
32
|
+
OrderOption.from_json json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def width_in_mils
|
37
|
+
@width_in_mils || 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def height_in_mils
|
41
|
+
@height_in_mils || 0
|
42
|
+
end
|
43
|
+
|
44
|
+
def approve!
|
45
|
+
json = Oshpark::client.approve_project id
|
46
|
+
reload_with(json)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "The oshpark gem must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
lib = File.expand_path(__FILE__, "../../")
|
8
|
+
app.files = Dir.glob("#{lib}/**/*.rb") + app.files
|
9
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Oshpark
|
2
|
+
class Token
|
3
|
+
|
4
|
+
attr_accessor :expires_at
|
5
|
+
|
6
|
+
def ttl
|
7
|
+
expires_at - Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
User.from_json 'id' => user_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def ttl= i
|
15
|
+
sel.expires_at = Time.now + i
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.attrs
|
19
|
+
%w| token ttl user_id |
|
20
|
+
end
|
21
|
+
|
22
|
+
include Model
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Oshpark
|
2
|
+
class Upload
|
3
|
+
def self.attrs
|
4
|
+
%w| id state original_filename error_message queued_at started_at completed_at errored_at failed_at project_id |
|
5
|
+
end
|
6
|
+
|
7
|
+
include Model
|
8
|
+
|
9
|
+
def self.create file
|
10
|
+
self.from_json(Oshpark::client.create_upload(file))
|
11
|
+
end
|
12
|
+
|
13
|
+
def project
|
14
|
+
Project.find project_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def queued_at
|
18
|
+
time_from @queued_at
|
19
|
+
end
|
20
|
+
|
21
|
+
def started_at
|
22
|
+
time_from @started_at
|
23
|
+
end
|
24
|
+
|
25
|
+
def completed_at
|
26
|
+
time_from @completed_at
|
27
|
+
end
|
28
|
+
|
29
|
+
def errored_at
|
30
|
+
time_from @errored_at
|
31
|
+
end
|
32
|
+
|
33
|
+
def failed_at
|
34
|
+
time_from @failed_at
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/oshpark/user.rb
ADDED
data/oshpark.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oshpark/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oshpark"
|
8
|
+
spec.version = Oshpark::VERSION
|
9
|
+
spec.authors = ["James Harton", "Henry Maddocks"]
|
10
|
+
spec.email = ["james@resistor.io", "henry@resistor.io"]
|
11
|
+
spec.summary = %q{API and command line client for oshpark.com}
|
12
|
+
spec.description = %q{API and command line client for PCB fabrication via oshpark.com}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
|
23
|
+
%w| cucumber rspec-core rspec-mocks rspec-its guard-rspec guard-cucumber guard-bundler pry rake byebug|.each do |gem|
|
24
|
+
spec.add_development_dependency gem
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.add_dependency 'micro_token'
|
28
|
+
spec.add_dependency 'thor'
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::Address do
|
4
|
+
describe ".initialize" do
|
5
|
+
let(:args) { {name: "Bob", address_line_1: "8 Nelson Street", address_line_2: "Petone", city: "Lower Hutt", country: "New Zealand"} }
|
6
|
+
|
7
|
+
subject { Oshpark::Address.new args }
|
8
|
+
it "creates an address" do
|
9
|
+
expect(subject.address_line_1).to eq "8 Nelson Street"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::Client do
|
4
|
+
let(:connection) { FakeClient.new "foo"}
|
5
|
+
subject { Oshpark::Client.new connection: connection }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'attempts to retrieve an API token immediately' do
|
9
|
+
subject
|
10
|
+
expect(connection.requests.last).to eq([:post, 'sessions', {}])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#authenticate' do
|
15
|
+
it 'attempts to authenticate an API token with a password' do
|
16
|
+
subject.authenticate 'email', with_password: 'pass'
|
17
|
+
expect(connection.requests.last).to eq([:post, 'sessions', {email: 'email', password: 'pass'}])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'attempts to authenticate an API token with an API secret' do
|
21
|
+
subject.authenticate 'email', with_api_secret: 'secret'
|
22
|
+
expect(connection.requests.last).to eq([:post, 'sessions', {email: 'email', api_key: 'add39dedbfe932ce383881dac4870bf417ebb79e1ec743e5c1e3bec574a2e821'}])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#projects' do
|
27
|
+
it 'retrieves a list of projects from the API' do
|
28
|
+
subject.projects
|
29
|
+
expect(connection.requests.last).to eq([:get, 'projects', {}])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#project' do
|
34
|
+
let(:token) { 'abcd1234' }
|
35
|
+
it 'retrieves a project from the API' do
|
36
|
+
subject.project token
|
37
|
+
expect(connection.requests.last).to eq([:get, "projects/#{token}", {}])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#approve_project' do
|
42
|
+
let(:token) { 'abcd1234' }
|
43
|
+
it 'approve a project via the API' do
|
44
|
+
subject.approve_project(token)
|
45
|
+
expect(connection.requests.last).to eq([:get, "projects/#{token}/approve", {}])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#destroy_project' do
|
50
|
+
let(:token) { 'abcd1234' }
|
51
|
+
it 'destroy a project via the API' do
|
52
|
+
expect(subject.destroy_project(token)).to eq true
|
53
|
+
expect(connection.requests.last).to eq([:delete, "projects/#{token}", {}])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#orders' do
|
58
|
+
it 'retrieves a list of orders from the API' do
|
59
|
+
subject.orders
|
60
|
+
expect(connection.requests.last).to eq([:get, 'orders', {}])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#order' do
|
65
|
+
let(:token) { 'abcd1234' }
|
66
|
+
it 'retrieves a order from the API' do
|
67
|
+
subject.order token
|
68
|
+
expect(connection.requests.last).to eq([:get, "orders/#{token}", {}])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#create_order' do
|
73
|
+
it "creates an order" do
|
74
|
+
subject.create_order
|
75
|
+
expect(connection.requests.last).to eq([:post, "orders", {}])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#add_order_item' do
|
80
|
+
let(:token) { 'abcd1234' }
|
81
|
+
let(:project_id) { '1234abcd' }
|
82
|
+
let(:quantity) { 6 }
|
83
|
+
it "add an order item to an order" do
|
84
|
+
subject.add_order_item token, project_id, quantity
|
85
|
+
expect(connection.requests.last).to eq([:put, "orders/#{token}/add_item", {:project_id=>"1234abcd", :quantity=>6}])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#set_order_address' do
|
90
|
+
let(:token) { 'abcd1234' }
|
91
|
+
let(:address) { Oshpark::Address.new name: "Bob", address_line_1: "8 Nelson Street", address_line_2: "Petone", city: "Lower Hutt", country: "New Zealand" }
|
92
|
+
it "set the delivery address for an order" do
|
93
|
+
subject.set_order_address token, address
|
94
|
+
expect(connection.requests.last).to eq([:put, "orders/#{token}/set_address", {"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil}])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#set_order_shipping_rate' do
|
99
|
+
let(:token) { 'abcd1234' }
|
100
|
+
let(:service_provider) { 'Bobs Mail'}
|
101
|
+
let(:service_name) { 'Overnight Delivery' }
|
102
|
+
it "sets the shipping rate for an order" do
|
103
|
+
subject.set_order_shipping_rate token, service_provider, service_name
|
104
|
+
expect(connection.requests.last).to eq([:put, "orders/#{token}/set_shipping_rate", {carrier_name: "Bobs Mail", service_name: "Overnight Delivery"}])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#checkout_order' do
|
109
|
+
let(:token) { 'abcd1234' }
|
110
|
+
it "checks out an order" do
|
111
|
+
subject.checkout_order token
|
112
|
+
expect(connection.requests.last).to eq([:put, "orders/#{token}/checkout", {}])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#cancel_order' do
|
117
|
+
let(:token) { 'abcd1234' }
|
118
|
+
it 'retrieves a order from the API' do
|
119
|
+
expect(subject.cancel_order(token)).to eq true
|
120
|
+
expect(connection.requests.last).to eq([:delete, "orders/#{token}", {}])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#panels' do
|
125
|
+
it 'retrieves a list of panels from the API' do
|
126
|
+
subject.panels
|
127
|
+
expect(connection.requests.last).to eq([:get, 'panels', {}])
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#panel' do
|
132
|
+
let(:token) { 'abcd1234' }
|
133
|
+
it 'retrieves a panel from the API' do
|
134
|
+
subject.panel token
|
135
|
+
expect(connection.requests.last).to eq([:get, "panels/#{token}", {}])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::Import do
|
4
|
+
subject { Oshpark::Import.new({}) }
|
5
|
+
it { should be_an Oshpark::Model }
|
6
|
+
|
7
|
+
%w| id state original_url original_filename error_message queued_at started_at completed_at errored_at failed_at project_id |.each do |attr|
|
8
|
+
it { should respond_to attr }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#project' do
|
12
|
+
it 'retrieves a project' do
|
13
|
+
allow(subject).to receive(:project_id).and_return('abcd1234')
|
14
|
+
expect(Oshpark::Project).to receive(:find).with('abcd1234')
|
15
|
+
subject.project
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::Layer do
|
4
|
+
subject { Oshpark::Layer.new({}) }
|
5
|
+
it { should be_an Oshpark::Model }
|
6
|
+
it { should respond_to :id }
|
7
|
+
it { should respond_to :name }
|
8
|
+
it { should respond_to :gerber_file_url }
|
9
|
+
it { should respond_to :image }
|
10
|
+
it { should respond_to :imported_from }
|
11
|
+
it { should respond_to :width_in_mils }
|
12
|
+
it { should respond_to :height_in_mils }
|
13
|
+
it { should respond_to :image }
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::Model do
|
4
|
+
let(:klass) do
|
5
|
+
Class.new do
|
6
|
+
def self.attrs
|
7
|
+
[ 'hello', 'goodbye' ]
|
8
|
+
end
|
9
|
+
def self.write_attrs
|
10
|
+
[ 'bob' ]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "included" do
|
17
|
+
before { klass.send :include, Oshpark::Model }
|
18
|
+
subject { klass.new({}) }
|
19
|
+
|
20
|
+
it "class ancestors should include Oshpark::Model::ClassMethods" do
|
21
|
+
expect(subject.class.ancestors).to include Oshpark::Model::ClassMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
it { should respond_to :hello }
|
25
|
+
it { should respond_to :goodbye }
|
26
|
+
it { should respond_to :bob= }
|
27
|
+
|
28
|
+
describe '.from_json' do
|
29
|
+
let(:json) do
|
30
|
+
{
|
31
|
+
'hello' => 'world',
|
32
|
+
'goodbye' => 'cruel world'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
subject { klass.from_json json }
|
36
|
+
|
37
|
+
its(:hello) { should eq 'world' }
|
38
|
+
its(:goodbye) { should eq 'cruel world' }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|