nokaya 0.0.1 → 0.0.2

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: 798577b2a41f1875075fb4ae509ea5f4999df74e
4
- data.tar.gz: 7ca1302cf20d022a9e22fdc4ea8736ae7c46776e
3
+ metadata.gz: 9a437d53d827e0c39fa5c65dddd1c0920178f82c
4
+ data.tar.gz: f017ad65a6324f89a17d0629a4061c6a8fe5b10b
5
5
  SHA512:
6
- metadata.gz: 9345f2189cb292fe591b68894afe8b706852ed528844ae4f8395d16be6bf21a1c58143602a8c6ffed494a0e2dbcef37b69236f855c0bf3affa4241cdd2d37b5d
7
- data.tar.gz: 02ddb1849c8e1206eb59fd659c64a84c344f277084429b7a8f8b72bbd8d37414cd27665b1b7ffb4d22f51887b26df8ab41032f45c460701110e78a127cc7fb76
6
+ metadata.gz: b2399328cb080b8604ed821b31db036c355b0492a32cb7a9ad0185012a8338d8e5f45b11aaeb59922a1284d6458e1315c07663b7310374319feba6f8bb2c541e
7
+ data.tar.gz: d9ab1abe1fc57243c56e95b587184a136beb6053ccb00476e3eeac7e7fcecaf972c35b1ce5c5d6e627148c4efe58843e1dfd1818e74fbfbff03cfabd528b3cea
@@ -0,0 +1,8 @@
1
+ # 0.0.2
2
+
3
+ - Error messages
4
+ - Option: name the file
5
+
6
+ # 0.0.1
7
+
8
+ - Basic feature for Instagram
data/README.md CHANGED
@@ -1,29 +1,23 @@
1
1
  # Nokaya
2
2
 
3
- TODO: Write a gem description
3
+ CLI to download photos from several online services including Instagram.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
5
+ Mac OS X only for the time being.
8
6
 
9
- gem 'nokaya'
7
+ ## Installation
10
8
 
11
- And then execute:
9
+ `gem install nokaya`
12
10
 
13
- $ bundle
11
+ ## Usage
14
12
 
15
- Or install it yourself as:
13
+ ### Instagram
16
14
 
17
- $ gem install nokaya
15
+ `nokaya -i url`
18
16
 
19
- ## Usage
17
+ `nokaya -i url -n file_name`
20
18
 
21
- TODO: Write usage instructions here
19
+ Example:
22
20
 
23
- ## Contributing
21
+ `nokaya -i http://instagram.com/p/noANAfjJ7B/`
24
22
 
25
- 1. Fork it ( https://github.com/[my-github-username]/nokaya/fork )
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
23
+ `nokaya -i http://instagram.com/p/noANAfjJ7B/ -n happydog`
@@ -3,18 +3,21 @@ module Nokaya
3
3
  class App < Thor
4
4
  package_name "Nokaya"
5
5
  require_relative 'getter'
6
+ require_relative 'image'
7
+ require_relative 'status'
6
8
 
7
9
  desc "instagram", "Get the main photo from an Instagram page (nokaya -i url)"
8
10
  map "-i" => :instagram
9
- option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension (nokaya -i url -n some_name)"
11
+ option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
10
12
  def instagram *args
13
+ abort Status.no_url if args.empty?
11
14
  nokaya = Getter.new options, :instagram, args
12
15
  page = nokaya.parse_page
13
16
  img_link = nokaya.get_link page
14
- path = nokaya.photo_name
15
- puts "Downloading #{img_link}, please wait...\n"
16
- nokaya.save_image path, img_link
17
- puts "\nImage saved in #{path}\n\n"
17
+ puts Status.downloading img_link
18
+ path = Image.photo_name nokaya
19
+ Image.save_image(path, nokaya.get_image(img_link))
20
+ puts Status.saved path
18
21
  end
19
22
  end
20
23
  end
@@ -17,26 +17,18 @@ module Nokaya
17
17
  @args.url
18
18
  end
19
19
  def get_image img_link
20
- open(img_link).read
20
+ begin
21
+ open(img_link).read
22
+ rescue
23
+ abort Status.no_can_do
24
+ end
21
25
  end
22
26
  def get_link page
23
27
  page.xpath("//meta[@property='og:image']/@content").first
24
28
  end
25
- def photo_name
26
- unless @args.options[:name]
27
- Dir.home + "/Downloads/#{@args.type.to_s}-#{Time.now.to_i}.jpg"
28
- else
29
- Dir.home + "/Downloads/#{@args.type.to_s}-#{@args.options[:name]}.jpg"
30
- end
31
- end
32
29
  def parse_page
33
30
  Nokogiri::HTML get_page_content
34
31
  end
35
- def save_image path, img_link
36
- f = File.new(path, "wb")
37
- f.puts(get_image img_link)
38
- f.close
39
- end
40
32
  private
41
33
  def get_page_content
42
34
  open @args.url
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+ class Image
4
+ def self.photo_name nokaya
5
+ unless nokaya.options[:name]
6
+ Dir.home + "/Downloads/#{nokaya.type.to_s}-#{Time.now.to_i}.jpg"
7
+ else
8
+ Dir.home + "/Downloads/#{nokaya.type.to_s}-#{nokaya.options[:name]}.jpg"
9
+ end
10
+ end
11
+ def self.save_image path, content
12
+ f = File.new(path, "wb")
13
+ f.puts(content)
14
+ f.close
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Nokaya
3
+ class Status
4
+ def self.downloading img_link
5
+ "\nDownloading #{img_link}, please wait...\n\n"
6
+ end
7
+ def self.saved path
8
+ "Image saved in #{path}\n\n"
9
+ end
10
+ def self.no_can_do
11
+ "Canceled: unable to get the page contents.\n\n"
12
+ end
13
+ def self.no_url
14
+ "\nYou have to specify a page URL.\n\n"
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Nokaya
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
@@ -202,6 +202,7 @@ extensions: []
202
202
  extra_rdoc_files: []
203
203
  files:
204
204
  - ".gitignore"
205
+ - CHANGELOG.md
205
206
  - Gemfile
206
207
  - Guardfile
207
208
  - LICENSE.txt
@@ -211,6 +212,8 @@ files:
211
212
  - lib/nokaya.rb
212
213
  - lib/nokaya/app.rb
213
214
  - lib/nokaya/getter.rb
215
+ - lib/nokaya/image.rb
216
+ - lib/nokaya/status.rb
214
217
  - lib/nokaya/version.rb
215
218
  - nokaya.gemspec
216
219
  - spec/nokaya_spec.rb