myshop 0.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 +7 -0
- data/bin/myshop +2 -0
- data/lib/config.rb +11 -0
- data/lib/my_shop.rb +50 -0
- data/lib/shopify_api_connector.rb +43 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: b314ba2f62dc048f8d561924c2ca6e50ce5230fb
|
|
4
|
+
data.tar.gz: 40639dd15d10f6068c9ba699f91be722736b20cb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e05f1ce01961870bc870159828550e2e845d542a12961d9d8488fa7f83c9845ab4a2f1078c609ef9c61380df5a256a90551f3f65e04438b5077378af5b6ed694
|
|
7
|
+
data.tar.gz: 825bf34526464ec57035d2e9f6572808162820a48aef70c5d71cf564d1f865b433b7c0c07a9420f7a6c3904fccd6dfa2bc7f3b69387e82c377639b0e6368a86b
|
data/bin/myshop
ADDED
data/lib/config.rb
ADDED
data/lib/my_shop.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'optparse'
|
|
3
|
+
require_relative 'shopify_api_connector'
|
|
4
|
+
require_relative 'config'
|
|
5
|
+
|
|
6
|
+
CALCULATE_REVENUE = 1
|
|
7
|
+
|
|
8
|
+
options = { :do_throughput_measurement => false, :query_string => '', :debug => false }
|
|
9
|
+
|
|
10
|
+
OptionParser.new do|opts|
|
|
11
|
+
opts.banner = "Usage: myshop [options] \nDefault paramaters aim to complete shopify's 2017 summer internship task."
|
|
12
|
+
|
|
13
|
+
opts.on('-t', '--host host', 'Host or domain name where your shop is.') do |host|
|
|
14
|
+
options[:host] = host
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
opts.on('-a', '--access-token access_token', 'Specify the acces token used when connecting to the Shopify API.') do |access_token|
|
|
18
|
+
options[:access_token] = access_token
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
opts.on('-c', '--calculate-revenu', 'Mode of operation (Default)') do
|
|
22
|
+
options[:mode] = CALCULATE_REVENUE
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
opts.on('-h', '--help', 'Displays help') do
|
|
26
|
+
puts "\n#{opts}"
|
|
27
|
+
puts
|
|
28
|
+
exit
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end.parse!
|
|
32
|
+
|
|
33
|
+
options[:host] = "shopicruit.myshopify.com" if options[:host].nil?
|
|
34
|
+
options[:access_token] = "c32313df0d0ef512ca64d5b336a0d7c6" if options[:access_token].nil?
|
|
35
|
+
|
|
36
|
+
config = Config.new(host: options[:host], access_token: options[:access_token])
|
|
37
|
+
api_connector = ShopifyApiConnector.new(config)
|
|
38
|
+
|
|
39
|
+
orders = api_connector.get_orders
|
|
40
|
+
|
|
41
|
+
options[:mode] = CALCULATE_REVENUE if options[:mode].nil?
|
|
42
|
+
|
|
43
|
+
case options[:mode]
|
|
44
|
+
when CALCULATE_REVENUE
|
|
45
|
+
total_revenue = 0.0
|
|
46
|
+
orders.each do |order|
|
|
47
|
+
total_revenue += order["total_price"].to_f
|
|
48
|
+
end
|
|
49
|
+
puts "Total Revenue: #{total_revenue.round(2)}"
|
|
50
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
require_relative 'config'
|
|
4
|
+
|
|
5
|
+
class ShopifyApiConnector
|
|
6
|
+
|
|
7
|
+
def initialize(config)
|
|
8
|
+
raise ArgumentError.new("Required class type 'Config' - recieved #{config.class}") unless config.kind_of? Config
|
|
9
|
+
@config = config
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get_orders
|
|
13
|
+
num_orders = get_num_orders
|
|
14
|
+
orders = nil
|
|
15
|
+
page_num = 1
|
|
16
|
+
while orders.nil? or orders.count < num_orders
|
|
17
|
+
uri = URI("https://#{@config.host}/admin/orders.json?page=#{page_num}&access_token=#{@config.access_token}")
|
|
18
|
+
Net::HTTP.start(uri.host, uri.port,
|
|
19
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
|
20
|
+
request = Net::HTTP::Get.new uri
|
|
21
|
+
|
|
22
|
+
response = http.request request # Net::HTTPResponse object
|
|
23
|
+
response_json = JSON.parse(response.body)
|
|
24
|
+
orders.nil? ? orders = response_json["orders"] : orders = orders + response_json["orders"]
|
|
25
|
+
end
|
|
26
|
+
page_num += 1
|
|
27
|
+
end
|
|
28
|
+
return orders
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_num_orders
|
|
32
|
+
uri = URI("https://#{@config.host}/admin/orders/count.json?access_token=#{@config.access_token}")
|
|
33
|
+
Net::HTTP.start(uri.host, uri.port,
|
|
34
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
|
35
|
+
request = Net::HTTP::Get.new uri
|
|
36
|
+
|
|
37
|
+
response = http.request request # Net::HTTPResponse object
|
|
38
|
+
return JSON.parse(response.body)["count"]
|
|
39
|
+
end
|
|
40
|
+
return nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: myshop
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Joel Scarfone
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Utility to get statistics from one's shopify store. Open source and easily
|
|
14
|
+
expandable.
|
|
15
|
+
email: joel.scarfone@carleton.com
|
|
16
|
+
executables:
|
|
17
|
+
- myshop
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- bin/myshop
|
|
22
|
+
- lib/config.rb
|
|
23
|
+
- lib/my_shop.rb
|
|
24
|
+
- lib/shopify_api_connector.rb
|
|
25
|
+
homepage: https://github.com/JoelScarfone/MyShop
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata: {}
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubyforge_project:
|
|
45
|
+
rubygems_version: 2.5.2
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Get statistics on your shopify store!.
|
|
49
|
+
test_files: []
|