pull_tempfile 0.1.0 → 0.2.0

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: caf9eb1fd40ac992ddd93ac1e53514c560d2c4c1
4
- data.tar.gz: 6a288c61ead7821e62d2cf4b89aa57d0039e9e7c
3
+ metadata.gz: 2b8db6c4f0a51d1d598b1e95c29ab654e49283c5
4
+ data.tar.gz: 4a40e696037bdfe68c6fec8b8522238a1882be8b
5
5
  SHA512:
6
- metadata.gz: 8618caa4f7c3cc2689d5ab7d36e0649ff2913e2a79089ec8edc42f86fca8bded6e6fa8935703bd0e87d7f2604525495de1c55a3ab558bf0c52b2af858d4eb51d
7
- data.tar.gz: c26e94ac0e8df02659ddb1ed61c872e2422e3f416b7f7c9a5ecd104939e5aa3a31fc46c00e744f0da870db79034b0db3a43217e56beb62001a5c5cb5f0ee9232
6
+ metadata.gz: e02a55e0b31d791c37be9997c5ce7b10488f61c2307a268cb943c206fe685ac2879f579647bc2851aa3900f2e75009d6fa334b02f0b0519458f965e2319655a1
7
+ data.tar.gz: 18f1ef0761e816e229aea6c3dc4720f06fd8c63ccd44243cac77cd57abbb0c97fe0bfe2c72b4b862fb98d8def92a29fc18b369ed6d666105e10e4b33e902491e
@@ -3,5 +3,5 @@ rvm:
3
3
  - 2.1.0
4
4
  - 2.2.3
5
5
  - 2.3.0
6
- before_install: gem install bundler -v 1.10.6
6
+ before_install: gem install bundler -v 1.11
7
7
 
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![Build Status](https://travis-ci.org/equivalent/pull_tempfile.svg?branch=master)](https://travis-ci.org/equivalent/pull_tempfile)
4
4
  [![Code Climate](https://codeclimate.com/github/equivalent/pull_tempfile/badges/gpa.svg)](https://codeclimate.com/github/equivalent/pull_tempfile)
5
5
 
6
+ Simple way how to download file from url to temporary file. (Please read more on "why" would you need to do this down bellow)
7
+
6
8
  ## Installation
7
9
 
8
10
  Add this line to your application's Gemfile:
@@ -21,18 +23,44 @@ Or install it yourself as:
21
23
 
22
24
  ## Usage
23
25
 
26
+
27
+ #### Simplest example
28
+
29
+ ```ruby
30
+ require 'pull_tempfile'
31
+
32
+ original_filename = 'no idea.png'
33
+ url = 'http://www.eq8.eu/no-idea.png'
34
+
35
+ file = PullTempfile.pull_tempfile(url: url, original_filename: original_filename)
36
+ file.unlink # delete file after you done
37
+
38
+ # ...or
39
+
40
+ PullTempfile.transaction(url: url, original_filename: original_filename) do |tmp_file|
41
+ puts tmp_file.path
42
+ # ...
43
+ end
24
44
  ```
45
+
46
+ `transaction` will automatically delete (`unlink`) the temporary file after block
47
+ finish.
48
+
49
+ #### Paperclip & Rails
50
+
51
+ ```ruby
52
+ require 'pull_tempfile'
53
+
25
54
  class Medium < ActiveRecord::Base
26
55
  has_attached_file :file
27
56
 
28
57
  # ...
29
58
  end
30
59
 
31
- require 'pull_tempfile'
32
-
33
60
  # when used as "AWS S3 browser upload" you can fetch original filename as "${filename}" metadata
34
61
  # or use some different way to determine the file name.
35
- original_filename = 'my face.jpg'
62
+ original_filename = 'no idea.png'
63
+ url = 'http://www.eq8.eu/no-idea.png'
36
64
 
37
65
  medium = Media.new
38
66
 
@@ -40,19 +68,8 @@ PullTempfile.transaction(url: url, original_filename: original_filename) do |tmp
40
68
  medium.file = tmp_file
41
69
  medium.save!
42
70
  end
43
-
44
71
  ```
45
72
 
46
- Transaction will automatically delete (`unlink`) the temporary file after block
47
- finish. If you want to keep the tmp file for longer you can use:
48
-
49
- ```
50
- file = PullTempfile.pull_tempfile(url: url, original_filename: original_filename)
51
- # ...
52
- file.unlink # delete file
53
- ```
54
-
55
-
56
73
  ## License
57
74
 
58
75
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -135,7 +152,7 @@ Run `bundle install`
135
152
 
136
153
  Next create new file `./lib/s3_helper.rb`
137
154
 
138
- ```
155
+ ```ruby
139
156
  require 'httparty' # gem
140
157
  module S3Helper
141
158
  def pull_asset(url:, destination:)
@@ -1,10 +1,32 @@
1
- require 'httparty' # gem
2
- require 'pathname' # standard Ruby lib
3
- require 'tempfile' # standard Ruby lib
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'pathname'
4
+ require 'tempfile'
4
5
 
5
6
  require "pull_tempfile/version"
6
7
 
7
8
  module PullTempfile
9
+ class Config
10
+ attr_writer :puller
11
+
12
+ def puller
13
+ @puller ||= ->(url){ Net::HTTP.get(URI.parse(url)) }
14
+ end
15
+ end
16
+
17
+ def self.config
18
+ @config ||= Config.new
19
+ end
20
+
21
+ # To use differnt puller you can do
22
+ #
23
+ # require 'httparty'
24
+ # PullTempfile.config.puller = ->(url){ HTTParty.get(url).parsed_response }
25
+ #
26
+ def self.puller
27
+ config.puller
28
+ end
29
+
8
30
  # Creates Temporary file
9
31
  #
10
32
  # file = PullTempfile.pull_tempfile(original_filename: "image asset.jpg", url: 'http://..../uaoeuoeueoauoueao' )
@@ -24,7 +46,7 @@ module PullTempfile
24
46
 
25
47
  file = Tempfile.new([tmp_file_name, extension])
26
48
  file.binmode
27
- file.write(HTTParty.get(url).parsed_response)
49
+ file.write(puller.call(url))
28
50
  file.close
29
51
  file
30
52
  end
@@ -1,3 +1,3 @@
1
1
  module PullTempfile
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "httparty", "~> 0.13"
23
22
  spec.add_development_dependency "bundler", "~> 1.11"
24
23
  spec.add_development_dependency "rake", "~> 10.0"
25
24
  spec.add_development_dependency "rspec", "~> 3.4"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pull_tempfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Valent
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-21 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: httparty
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.13'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.13'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement