printfection 1.0.0 → 1.0.1

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: 988cf5fbd90dab60a47312201529a4a7c2b4c8db
4
- data.tar.gz: 1ad04c530a77b106a8e0fe8c9a834d8eda1e4a48
3
+ metadata.gz: 62ca1781e47fce515995fe4b3467e9f53b268b44
4
+ data.tar.gz: b3c3967aff21db9f3222ece0a2731a6338d2351b
5
5
  SHA512:
6
- metadata.gz: e609441046a5bd41cfbce861c1c296257104b3ce6b1c233f40fb59125794b8dc8cf7f89c108f0e350df301b8695bd0b770ae8b97f1055555bc036a54cf120730
7
- data.tar.gz: a79796194853ee8cedfa0bdf06f06e4f348dc03fa73b64d2132fea0372a68028556bab67d8710ba5a3983183885953c99aa3600e20a8c3a537b16c1be7b4571b
6
+ metadata.gz: 6cb26e1e083fc3f3aaac01d8dd553268368b9f621ff590a0d943aa2e2e628fd2b75157927350a9527b1b911963802ef586ea97b7ddf2797e391aa2dcecd042aa
7
+ data.tar.gz: 47cd784a3c53ed225c3320ec29c7b622df8d09a254cd245821ed651a74661dda34ca2b10f62101a1dccf64fddcc5f2c36d9dd8a993a355616ecd332dd86d36b6
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sinatra"
4
+ gem "printfection", :path => "../../../"
5
+
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: ../../../
3
+ specs:
4
+ printfection (1.0.0)
5
+ hashie (~> 3.3.1)
6
+ rest-client (~> 1.7.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ hashie (3.3.2)
12
+ mime-types (2.4.3)
13
+ netrc (0.8.0)
14
+ rack (1.5.2)
15
+ rack-protection (1.5.3)
16
+ rack
17
+ rest-client (1.7.2)
18
+ mime-types (>= 1.16, < 3.0)
19
+ netrc (~> 0.7)
20
+ sinatra (1.4.5)
21
+ rack (~> 1.4)
22
+ rack-protection (~> 1.4)
23
+ tilt (~> 1.3, >= 1.3.4)
24
+ tilt (1.4.1)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ printfection!
31
+ sinatra
@@ -0,0 +1,40 @@
1
+ require 'sinatra'
2
+ require 'printfection'
3
+ require 'logger'
4
+ Logger.class_eval { alias :write :'<<' }
5
+
6
+ $logger = ::Logger.new(STDOUT)
7
+
8
+ PF = Printfection
9
+ PF.api_token = ENV['PRINTFECTION_API_TOKEN']
10
+ PF.logger = $logger
11
+
12
+ class App < Sinatra::Base
13
+ use Rack::MethodOverride
14
+
15
+ configure do
16
+ use Rack::CommonLogger, $logger
17
+ end
18
+
19
+ get "/" do
20
+ @orders = PF::Order.all limit: 5
21
+ @campaigns = PF::Campaign.all
22
+ erb :dashboard
23
+ end
24
+
25
+ get "/orders" do
26
+ @orders = PF::Order.all
27
+ erb :orders
28
+ end
29
+
30
+ get "/orders/:id" do
31
+ @order = PF::Order.retrieve(params[:id])
32
+ erb :order
33
+ end
34
+
35
+ get "/campaigns/:id" do
36
+ @campaign = PF::Campaign.retrieve(params[:id])
37
+ erb :campaign
38
+ end
39
+ end
40
+
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require
5
+
6
+ require './app'
7
+ run App
8
+
@@ -0,0 +1,37 @@
1
+ <h1><%= @campaign.name %></h1>
2
+
3
+ <h3>Campaign Details</h3>
4
+
5
+ <table class="table">
6
+ <tr>
7
+ <td><strong>id</strong></td>
8
+ <td><%= @campaign.id %></td>
9
+ </tr>
10
+ <tr>
11
+ <td><strong>name</strong></td>
12
+ <td><%= @campaign.name %></td>
13
+ </tr>
14
+ <tr>
15
+ <td><strong>type</strong></td>
16
+ <td><%= @campaign.type %></td>
17
+ </tr>
18
+ <tr>
19
+ <td><strong>active</strong></td>
20
+ <td><%= @campaign.active %></td>
21
+ </tr>
22
+ <tr>
23
+ <td><strong>archived</strong></td>
24
+ <td><%= @campaign.archived %></td>
25
+ </tr>
26
+ <tr>
27
+ <td><strong>url</strong></td>
28
+ <td><%= @campaign.url %></td>
29
+ </tr>
30
+ <tr>
31
+ <td><strong>created_at</strong></td>
32
+ <td><%= @campaign.created_at %></td>
33
+ </tr>
34
+ </table>
35
+
36
+ <p><a href="/">&laquo; Dashboard</a></p>
37
+
@@ -0,0 +1,50 @@
1
+ <h1>Campaigns</h1>
2
+
3
+ <table class="table">
4
+ <thead>
5
+ <tr>
6
+ <th>ID</th>
7
+ <th>Name</th>
8
+ <th>Type</th>
9
+ <th>Active</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% @campaigns.each do |campaign| %>
14
+ <tr>
15
+ <td><a href="/campaigns/<%= campaign.id %>"><%= campaign.id %></a></td>
16
+ <td><%= campaign.name %></td>
17
+ <td><%= campaign.type %></td>
18
+ <td><%= campaign.active %></td>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
23
+
24
+ <br /><br />
25
+
26
+ <h1>Recent Orders</h1>
27
+
28
+ <table class="table">
29
+ <thead>
30
+ <tr>
31
+ <th>ID</th>
32
+ <th>Ship To</th>
33
+ <th>Status</th>
34
+ <th>Campaign</th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ <% @orders.each do |order| %>
39
+ <tr>
40
+ <td><a href="/orders/<%= order.id %>"><%= order.id %></a></td>
41
+ <td><%= order.ship_to.name %>, <%= order.ship_to.city %>, <%= order.ship_to.state %> <%= order.ship_to.zip_code %></td>
42
+ <td><%= order.status %></td>
43
+ <td><a href="/campaigns/<%= order.campaign_id %>"><%= order.campaign.name %></a></td>
44
+ </tr>
45
+ <% end %>
46
+ </tbody>
47
+ </table>
48
+
49
+ <p><a href="/orders">All orders &raquo;</a></p>
50
+
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
5
+ </head>
6
+ <body>
7
+ <div class="container">
8
+ <%= yield %>
9
+ </div><!-- /.container -->
10
+ </body>
11
+ </html>
12
+
@@ -0,0 +1,123 @@
1
+ <h1>Order #<%= @order.id %></h1>
2
+
3
+ <p><a href="/orders">&laquo; All orders</a></p>
4
+
5
+ <h3>Order Details</h3>
6
+
7
+ <table class="table">
8
+ <tr>
9
+ <td><strong>ID</strong></td>
10
+ <td><%= @order.id %></td>
11
+ </tr>
12
+ <tr>
13
+ <td><strong>Campaign</strong></td>
14
+ <td><a href="/campaigns/<%= @order.campaign.id %>"><%= @order.campaign.name %></a></td>
15
+ </tr>
16
+ <tr>
17
+ <td><strong>Status</strong></td>
18
+ <td><%= @order.status %></td>
19
+ </tr>
20
+ <tr>
21
+ <td><strong>Code</strong></td>
22
+ <td><%= @order.code %></td>
23
+ </tr>
24
+ <tr>
25
+ <td><strong>URL</strong></td>
26
+ <td><%= @order.url %></td>
27
+ </tr>
28
+ <tr>
29
+ <td><strong>Gift</strong></td>
30
+ <td><%= @order.gift %></td>
31
+ </tr>
32
+ <tr>
33
+ <td><strong>Gift Message</strong></td>
34
+ <td><%= @order.gift_message %></td>
35
+ </tr>
36
+ <tr>
37
+ <td><strong>Date</strong></td>
38
+ <td><%= @order.created_at.strftime('%m/%d/%Y') %></td>
39
+ </tr>
40
+ </table>
41
+
42
+ <br />
43
+ <br />
44
+
45
+ <h3>Line Items</h3>
46
+
47
+ <table class="table">
48
+ <thead>
49
+ <tr>
50
+ <th></th>
51
+ <th>Item</th>
52
+ <th>Size</th>
53
+ <th>Quantity</th>
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ <% @order.line_items.each do |line_item| %>
58
+ <tr>
59
+ <td>
60
+ <% line_item.item.assets.each do |asset| %>
61
+ <div>
62
+ <img src="<%= asset.url %>" width="90" />
63
+ <%= asset.perspective %>
64
+ </div>
65
+ </div>
66
+ <% end %>
67
+ </td>
68
+ <td><%= line_item.item.name %> - <%= line_item.item.type %> - <%= line_item.item.color %></td>
69
+ <td><%= line_item.size.name %></td>
70
+ <td><%= line_item.quantity %></td>
71
+ </tr>
72
+ <% end %>
73
+ </tbody>
74
+ </table>
75
+
76
+ <br /><br />
77
+
78
+ <h3>Shipping Address</h3>
79
+
80
+ <table class="table">
81
+ <tr>
82
+ <td><strong>Name</strong></td>
83
+ <td><%= @order.ship_to.name %></td>
84
+ </tr>
85
+ <tr>
86
+ <td><strong>Address</strong></td>
87
+ <td><%= @order.ship_to.address %></td>
88
+ </tr>
89
+ <tr>
90
+ <td><strong>Address 2</strong></td>
91
+ <td><%= @order.ship_to.address2 %></td>
92
+ </tr>
93
+ <tr>
94
+ <td><strong>Company</strong></td>
95
+ <td><%= @order.ship_to.company %></td>
96
+ </tr>
97
+ <tr>
98
+ <td><strong>City</strong></td>
99
+ <td><%= @order.ship_to.city %></td>
100
+ </tr>
101
+ <tr>
102
+ <td><strong>State</strong></td>
103
+ <td><%= @order.ship_to.state %></td>
104
+ </tr>
105
+ <tr>
106
+ <td><strong>Zip</strong></td>
107
+ <td><%= @order.ship_to.zip_code %></td>
108
+ </tr>
109
+ <tr>
110
+ <td><strong>Country</strong></td>
111
+ <td><%= @order.ship_to.country %></td>
112
+ </tr>
113
+ <tr>
114
+ <td><strong>Email</strong></td>
115
+ <td><%= @order.ship_to.email %></td>
116
+ </tr>
117
+ <tr>
118
+ <td><strong>Phone</strong></td>
119
+ <td><%= @order.ship_to.phone %></td>
120
+ </tr>
121
+ </table>
122
+
123
+
@@ -0,0 +1,25 @@
1
+ <h1>Orders</h1>
2
+
3
+ <table class="table">
4
+ <thead>
5
+ <tr>
6
+ <th>ID</th>
7
+ <th>Ship To</th>
8
+ <th>Status</th>
9
+ <th>Campaign</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% @orders.each do |order| %>
14
+ <tr>
15
+ <td><a href="/orders/<%= order.id %>"><%= order.id %></a></td>
16
+ <td><%= order.ship_to.name %>, <%= order.ship_to.city %>, <%= order.ship_to.state %> <%= order.ship_to.zip_code %></td>
17
+ <td><%= order.status %></td>
18
+ <td><a href="/campaigns/<%= order.campaign_id %>"><%= order.campaign.name %></a></td>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
23
+
24
+ <p><a href="/">&laquo; Dashboard</a></p>
25
+
@@ -2,6 +2,7 @@ require "json"
2
2
  require "hashie"
3
3
  require "restclient"
4
4
  require "forwardable"
5
+ require "date"
5
6
 
6
7
  require "printfection/version"
7
8
  require "printfection/util"
@@ -2,7 +2,8 @@ module Printfection
2
2
  module API
3
3
  ENDPOINT = "api.printfection.com/v2/"
4
4
 
5
- attr_accessor :api_token, :debug_mode
5
+ attr_accessor :api_token
6
+ attr_accessor :logger
6
7
 
7
8
  def get(uri="/", params={})
8
9
  request :get, uri, params
@@ -25,6 +26,10 @@ module Printfection
25
26
  uri = Util.join_uri(ENDPOINT, uri)
26
27
  url = "https://#{api_token}:@#{uri}"
27
28
 
29
+ unless logger.nil?
30
+ logger.info "[Printfection] #{verb.upcase} #{url}"
31
+ end
32
+
28
33
  response = case verb
29
34
  when :get; RestClient.get url, :params => params, :accept => :json
30
35
  when :post; RestClient.post url, params.to_json, :accept => :json, :content_type => :json
@@ -45,8 +50,6 @@ module Printfection
45
50
  private
46
51
 
47
52
  def perform_request(&block)
48
- return yield if debug_mode
49
-
50
53
  begin
51
54
  yield
52
55
 
@@ -16,6 +16,14 @@ module Printfection
16
16
  "/lineitems"
17
17
  end
18
18
 
19
+ def item
20
+ @item ||= Item.retrieve(item_id)
21
+ end
22
+
23
+ def size
24
+ @size ||= item.sizes.find { |s| s.id == size_id }
25
+ end
26
+
19
27
  end
20
28
  end
21
29
 
@@ -29,7 +29,7 @@ module Printfection
29
29
  end
30
30
 
31
31
  def line_items
32
- Relation.new(
32
+ @line_items ||= Relation.new(
33
33
  parent: self,
34
34
  children: self[:line_items],
35
35
  klass: LineItem,
@@ -40,7 +40,7 @@ module Printfection
40
40
  end
41
41
 
42
42
  def campaign
43
- Campaign.retrieve(campaign_id)
43
+ @campaign ||= Campaign.retrieve(campaign_id)
44
44
  end
45
45
 
46
46
  def place
@@ -1,4 +1,4 @@
1
1
  module Printfection
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: printfection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey O'Hara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -108,6 +108,15 @@ files:
108
108
  - LICENSE.txt
109
109
  - README.md
110
110
  - Rakefile
111
+ - examples/web/Gemfile
112
+ - examples/web/Gemfile.lock
113
+ - examples/web/app.rb
114
+ - examples/web/config.ru
115
+ - examples/web/views/campaign.erb
116
+ - examples/web/views/dashboard.erb
117
+ - examples/web/views/layout.erb
118
+ - examples/web/views/order.erb
119
+ - examples/web/views/orders.erb
111
120
  - lib/printfection.rb
112
121
  - lib/printfection/actions.rb
113
122
  - lib/printfection/address.rb