This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'uri' | ||
require 'net/http' | ||
require 'net/https' | ||
require 'cgi' | ||
|
||
class AftershipTracking < ActiveRecord::Base | ||
attr_accessible :tracking, :email, :order_number, :add_to_aftership | ||
|
||
def self.add_to_aftership | ||
AftershipTracking.where(:add_to_aftership => nil).each do |tracking| | ||
post_data = {"consumer_key" => Spree::Aftership::Config[:consumer_key], "consumer_secret" => Spree::Aftership::Config[:consumer_secret], "tracking_number" => tracking.tracking, "email" => tracking.email, "title" => "Spree Order: #{tracking.order_number}"} | ||
|
||
begin | ||
url = URI.parse("https://www.aftership.com/en/api/add-tracking/") | ||
req = Net::HTTP::Post.new(url.path) | ||
req.set_form_data(post_data) | ||
|
||
sock = Net::HTTP.new(url.host, url.port) | ||
sock.use_ssl = true | ||
res = sock.start { |http| http.request(req) } | ||
|
||
case res | ||
when Net::HTTPOK | ||
tracking.update_attribute(:add_to_aftership, Time.now) | ||
else | ||
logger.error 'Unable to add tracking number to AfterShip!' | ||
end | ||
rescue Exception => e | ||
logger.error "AfterShip error:#{e.message}" | ||
end | ||
end | ||
AftershipTracking.where("add_to_aftership <= ?", 1.month.ago).destroy_all | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateAftershipTrackings < ActiveRecord::Migration | ||
def change | ||
create_table :aftership_trackings do |t| | ||
t.string :tracking | ||
t.string :email | ||
t.string :order_number | ||
t.datetime :add_to_aftership | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[1m[36m (0.3ms)[0m [1mselect owner_id, owner_type, name, value from spree_preferences where `key` is null[0m | ||
SQLite3::SQLException: no such table: spree_preferences: select owner_id, owner_type, name, value from spree_preferences where `key` is null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe AftershipTracking do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |