ApApiTools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 880d421fd842993c4c4f53ae401fe7b49b694eec
4
+ data.tar.gz: 7dc72c1d3912bf6370a0c0493e497c518be60c2c
5
+ SHA512:
6
+ metadata.gz: 9cc78ad03a8f0f4da2990f039d3c1a27a3e1607d253ab92a8f1e261e24d0d3b974b1cc078d1edd77a3cdf99f082957ec2494efda0bc83715eb4e885a8958e251
7
+ data.tar.gz: 79b231b6b9c20961bfbc95d8ee7d46e596a67a24b6ebcc543c02648eb6bbe4f4c4c55ce6829974f34cf22317cdf1fd3af2837f102959ab54e6d26cf79b5f39c1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sean.smithy1@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in APTools.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sean Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # APTools
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/APTools`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'APTools'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install APTools
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/APTools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the APTools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/APTools/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ap_api_tools/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ApApiTools"
8
+ spec.version = ApApiTools::VERSION
9
+ spec.authors = ["Sean Smith"]
10
+ spec.email = ["sean.smith@comapps.net"]
11
+
12
+ spec.summary = %q{API Tools for Artists Place}
13
+ spec.description = %q{Various Tools to interact with AP from a console. Bulk upload, Image downloads}
14
+ spec.homepage = "https://www.artistsplace.com.au"
15
+ spec.license = "MIT"
16
+
17
+ spec.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'
18
+ spec.add_runtime_dependency 'http'
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ap_api_tools"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ class Artist
2
+
3
+ def initialize
4
+ @artists=get_artists
5
+ end
6
+
7
+ def get_artists
8
+ artist_return=HTTP.headers(
9
+ :accept => "application/json",
10
+ 'X-Spree-Token': "#{ApApiTools::API_KEY}"
11
+ )
12
+ .get("#{ApApiTools::HOST}/taxonomies?q[name_eq]=Artist")
13
+ JSON.parse(artist_return.body, symbolize_names: true)
14
+ end
15
+
16
+ def list
17
+ i=0
18
+ # .first as there should only ever be one due to query above
19
+ @artists[:taxonomies].first[:root][:taxons].map{ |a| { seq: i+=1, id: a[:id], name: a[:name ] } }
20
+ end
21
+
22
+ end
@@ -0,0 +1,36 @@
1
+ class Product
2
+
3
+ #Instance
4
+
5
+ def initialize(p, id=nil)
6
+ @product = p
7
+ if id
8
+ @product = get_product(id)
9
+ end
10
+ end
11
+
12
+ def images
13
+ @product[:master][:images]
14
+ end
15
+
16
+ def has_images
17
+ @product[:master][:images].count > 0
18
+ end
19
+
20
+ private
21
+
22
+ def get_product(id)
23
+ # Get Product
24
+ end
25
+
26
+ def self.get_products(artist_id, page_no=1)
27
+ puts "Getting Products: #{page_no}"
28
+ product_return=HTTP.headers(
29
+ :accept => "application/json",
30
+ 'X-Spree-Token': "#{ApApiTools::API_KEY}"
31
+ )
32
+ .get("#{ApApiTools::HOST}/products/?q[taxon_ids)=artist_id&page=#{page_no}")
33
+
34
+ JSON.parse(product_return.body, symbolize_names: true)
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ module Utils
2
+
3
+ def self.internet?
4
+ begin
5
+ true if open("http://www.google.com/")
6
+ rescue
7
+ false
8
+ end
9
+ end
10
+
11
+ def self.clear
12
+ system('clear') || system('cls')
13
+ end
14
+
15
+ def self.artist_products_menu(products)
16
+ line_items=[]
17
+ products.each do |product|
18
+ obj_p=Product.new(product)
19
+ if obj_p.has_images
20
+ obj_p.images.each do |img|
21
+ line_items << { id: product[:id], name: product[:name], num_img: product[:master][:images].count, image_id: img[:id], file_name: img[:attachment_file_name] }
22
+ end
23
+ else
24
+ line_items << { id: product[:id], name: product[:name ], num_img: product[:master][:images].count, image_id: '', file_name: 'NO ARTWORK' }
25
+ end
26
+ end
27
+ line_items
28
+ end
29
+
30
+ def self.download(url, dir=nil)
31
+ if dir.nil? || dir == ''
32
+ dir = File.join(Dir.home,"Downloads")
33
+ end
34
+
35
+ file=File.basename(url)
36
+ File.open(File.join(dir,file), "w") do |f|
37
+ f.write(HTTP.get(url).body)
38
+ f.close
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ApApiTools
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,122 @@
1
+ #!/bin/env ruby
2
+ require_relative "ap_api_tools/version"
3
+ require_relative 'ap_api_tools/utils'
4
+ require_relative 'ap_api_tools/product'
5
+ require_relative 'ap_api_tools/artist'
6
+
7
+ module ApApiTools
8
+ require 'json'
9
+ require 'http'
10
+ require 'open-uri'
11
+
12
+
13
+ HOST = ENV['AP_API_HOST']
14
+ API_KEY = ENV['AP_API_KEY']
15
+
16
+ def self.prompt
17
+ puts
18
+ puts "To download use comma delimited seq numbers eg: 1,3,5 or (A)ll"
19
+ puts "To change pages (N)ext or (P)revious"
20
+ print "Select : "
21
+ @select=gets.chomp.to_s
22
+ end
23
+
24
+ loop do
25
+
26
+ Utils.clear
27
+
28
+ if Utils.internet? == false
29
+ puts "Internet is required"
30
+ exit
31
+ end
32
+
33
+ # Menu
34
+ puts "This Utility will download Images by type for an Artist"
35
+ puts "-------------------------------------------------------"
36
+ puts
37
+
38
+ artists = Artist.new
39
+ artists.list.each do |a|
40
+ puts "#{a[:seq]} #{a[:name]}"
41
+ end
42
+
43
+ print "\nSelect Artist (1..) : "
44
+ a_select=gets.to_i
45
+
46
+ puts
47
+ puts "This Artist has this list of artworks"
48
+ puts "-"*38
49
+
50
+ page=1
51
+
52
+ loop do
53
+ artworks=Product.get_products(a_select, page)
54
+ printf("%-3s %-3s %-20s %3s %-20s \n\n", 'Seq', 'ID', 'Name', "I-ID", "Name")
55
+
56
+ i=1
57
+ Utils.artist_products_menu(artworks[:products]).each do |value|
58
+ printf("%-3s %-3s %-20s %-3s %-20s \n", i.to_s, value[:id].to_s, value[:name], value[:image_id].to_s, value[:file_name] )
59
+ i+=1
60
+ end
61
+ puts "page: #{artworks[:current_page].to_s} of #{artworks[:pages].to_s}"
62
+
63
+ loop do
64
+ prompt
65
+ case @select.downcase
66
+ when "p"
67
+ if artworks[:current_page]-1 == 0
68
+ puts "** Already at first page"
69
+ else
70
+ page=artworks[:current_page]-1
71
+ break
72
+ end
73
+ when "n"
74
+ if artworks[:current_page]+1 > artworks[:pages]
75
+ puts "** Already at last page"
76
+ else
77
+ page=artworks[:current_page]+1
78
+ break
79
+ end
80
+ when "a"
81
+ puts
82
+ print "Directory (default Home\\Downloads) : "
83
+ directory=gets.chomp
84
+ artworks[:products].each do |art|
85
+ p=Product.new(art)
86
+ # Test for images
87
+ if p.has_images
88
+ p.images.each do |img|
89
+ # All Artworks
90
+ Utils.download(img[:product_url], directory)
91
+ end
92
+ end
93
+ end
94
+ break
95
+ else
96
+ # Download Numbered Items
97
+ puts
98
+ print "Directory (default Home\\Downloads) : "
99
+ directory=gets.chomp
100
+ to_print = @select.split(',').map { |e| e.chomp.to_i }
101
+ to_print.each do |product_seq|
102
+ p=Product.new(artworks[:products][product_seq-1])
103
+ if p.has_images
104
+ p.images.each do |img|
105
+ # All Artworks
106
+ Utils.download(img[:product_url], directory)
107
+ end
108
+ end
109
+ end
110
+ break
111
+ end #Case
112
+ end #Loop Case
113
+ end #Loop Outer
114
+
115
+ print 'Quit (Y/N) :'
116
+ quit=gets.chomp.to_s
117
+
118
+ break if quit.downcase == 'y'
119
+
120
+ end #Loop
121
+
122
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ApApiTools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: http
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: Various Tools to interact with AP from a console. Bulk upload, Image
90
+ downloads
91
+ email:
92
+ - sean.smith@comapps.net
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".rspec"
99
+ - ".travis.yml"
100
+ - CODE_OF_CONDUCT.md
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - ap_api_tools.gemspec
106
+ - bin/console
107
+ - bin/setup
108
+ - lib/ap_api_tools.rb
109
+ - lib/ap_api_tools/artist.rb
110
+ - lib/ap_api_tools/product.rb
111
+ - lib/ap_api_tools/utils.rb
112
+ - lib/ap_api_tools/version.rb
113
+ homepage: https://www.artistsplace.com.au
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ allowed_push_host: https://rubygems.org
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.10
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: API Tools for Artists Place
138
+ test_files: []