inky 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73dfc9c82a669d92077f6ed7c56e6be5c47cb09e
4
+ data.tar.gz: ea0a899b7ddfe49302628c9480b5e5bd81cf73c4
5
+ SHA512:
6
+ metadata.gz: fe7c749ebca1d1b70dd077d23a111fc6df6a522b4082b5fe5e93b899faf9469ac5d039ed8559e85f7ea444d003b456c1cc84b94bc568df7b9e26f661ebc7cd27
7
+ data.tar.gz: c88bc15d94fe7dfcf5d9412e2257a7f3eaa06e84c3fb372aeaf8c30b4788ee59426d9488f75db341ceda054539de2d6563874c78ffacbf26d3bd015da0372df5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ ## Inky
2
+
3
+ A ruby client for [filepicker.io](http://filepicker.io). Built on top of the Filepicker
4
+ [REST API](https://developers.filepicker.io/docs/web/rest/).
5
+
6
+ ### Installation
7
+
8
+ Add this to your gemfile.rb:
9
+
10
+ ```
11
+ gem 'inky'
12
+ ```
13
+
14
+ ### Basic Usage
15
+
16
+ How to view information about existing files.
17
+
18
+ ```ruby
19
+ file = Inky::File.new('hFHUCB3iTxyMzseuWOgG')
20
+ file.uid
21
+ file.md5
22
+ file.mimetype
23
+ file.uploaded
24
+ file.container
25
+ file.writeable
26
+ file.filename
27
+ file.location
28
+ file.key
29
+ file.path
30
+ file.size
31
+
32
+ file.metadata # hash of all available metadata
33
+ ```
34
+
35
+ ### Storing files
36
+
37
+ First, authorize your Filepicker account. You must have a paid plan for cloud storage to work.
38
+
39
+ ```ruby
40
+ Inky.authorize! 'MyApiKey1234455665'
41
+ ```
42
+
43
+ To upload a local file:
44
+
45
+ ```ruby
46
+ Inky::File.from_file(File.open('my_file.png')).save!
47
+
48
+ # this is equivalent to:
49
+ file = Inky::File.new
50
+ file.local_file = File.open('my_file.png')
51
+ file.save!
52
+ ```
53
+
54
+ To save from a URL:
55
+
56
+ ```ruby
57
+ Inky::File.from_url('http://example.com/my_file.png').save!
58
+
59
+ # this is equivalent to:
60
+ file = Inky::File.new
61
+ file.remote_url = 'http://example.com/my_file.png'
62
+ file.save!
63
+ ```
64
+
65
+ ### Configuration
66
+
67
+ ```ruby
68
+ # file#save accepts several options:
69
+ file.save! location: 'S3', # Other options include 'azure', 'rackspace', 'dropbox'
70
+ filename: 'my_cool_file.ogg',
71
+ mimetype: 'application/ogg',
72
+ path: '/my_cool_files/1234.png', # path to store on cloud storage
73
+ container: 'myapp-development', # container/bucket on cloud storage
74
+ access: 'public' # defaults to 'private'
75
+ ```
76
+
77
+ ### Updating an existing file
78
+
79
+ `file.save!` can be used to update an existing file with new content from a local file or url:
80
+
81
+ ```ruby
82
+ # Updating an existing file
83
+ file = Inky::File.new('hFHUCB3iTxyMzseuWOgG')
84
+ file.local_file = File.open('my_new_file.ogg')
85
+ file.save!
86
+
87
+ file = Inky::File.new('hFHUCB3iTxyMzseuWOgG')
88
+ file.remote_url = 'http://example.com/my_new_file.ogg'
89
+ file.save!
90
+ ```
91
+
92
+ ### Todo
93
+
94
+ * Support security policies
95
+ * Support basic/temporary FP uploads (without S3/cloud storage)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/inky.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'inky/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'inky'
7
+ spec.version = Inky::VERSION
8
+ spec.authors = ['Smudge']
9
+ spec.email = ['nathan@ngriffith.com']
10
+ spec.summary = "A ruby client for filepicker.io's REST API"
11
+ spec.description = "A ruby client for filepicker.io's REST API"
12
+ spec.homepage = ''
13
+ spec.license = ''
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+
23
+ spec.add_dependency 'addressable', '>= 2.2.0'
24
+ spec.add_dependency 'rest-client', '>= 1.7.0'
25
+ spec.add_dependency 'activesupport', '>= 3.0.0'
26
+ end
data/lib/inky.rb ADDED
@@ -0,0 +1,12 @@
1
+ require_relative 'inky/file'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+
4
+ module Inky
5
+ BASE_URL = 'https://www.filepicker.io/api'
6
+
7
+ mattr_accessor :api_key
8
+
9
+ def self.authorize!(api_key)
10
+ self.api_key = api_key
11
+ end
12
+ end
data/lib/inky/file.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'rest_client'
2
+ require 'addressable/uri'
3
+
4
+ module Inky
5
+ class File
6
+ METADATA_FIELDS = :md5, :mimetype, :uploaded, :container, :writeable,
7
+ :filename, :location, :key, :path, :size, :width,
8
+ :height
9
+ MF_ARGS = METADATA_FIELDS.each_with_object({}) { |f, h| h[f] = true }
10
+
11
+ attr_accessor(*METADATA_FIELDS)
12
+ attr_accessor :uid, :local_file, :remote_url, :metadata
13
+
14
+ def initialize(value = nil)
15
+ return unless value
16
+ self.uid = value
17
+ request_metadata
18
+ end
19
+
20
+ def self.from_file(file)
21
+ self.local_file = value
22
+ end
23
+
24
+ def self.from_url(url)
25
+ self.remote_url = value
26
+ end
27
+
28
+ def url
29
+ "#{BASE_URL}/file/#{uid}"
30
+ end
31
+
32
+ def save!(opts = {})
33
+ opts = { location: 's3', key: Inky.api_key }.merge(opts)
34
+ handle_post_response RestClient.post(post_url(opts), post_opts)
35
+ self
36
+ end
37
+
38
+ private
39
+
40
+ def post_url(opts)
41
+ location = opts.delete(:location)
42
+ post_url = Addressable::URI.parse(uid ? url : store_url(location))
43
+ post_url.query_values = opts
44
+ post_url.to_s
45
+ end
46
+
47
+ def post_opts
48
+ { url: remote_url, fileUpload: local_file }.delete_if { |_, v| v.nil? }
49
+ end
50
+
51
+ def handle_post_response(response)
52
+ self.uid = JSON.parse(response)['url'].split('/').last
53
+ request_metadata
54
+ self.remote_url = self.local_file = nil
55
+ end
56
+
57
+ def store_url(location)
58
+ "#{BASE_URL}/store/#{location}"
59
+ end
60
+
61
+ def request_metadata
62
+ return unless uid
63
+ response = RestClient.get "#{url}/metadata", params: MF_ARGS
64
+ self.metadata = JSON.parse(response)
65
+ METADATA_FIELDS.each { |f| send("#{f}=", metadata[f.to_s]) }
66
+ end
67
+
68
+ def valid_url?(url)
69
+ (parsed = Addressable::URI.parse(url)) &&
70
+ %w(http https).include?(parsed.scheme)
71
+ rescue Addressable::URI::InvalidURIError
72
+ false
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ # Inky.authorize!('AEqf74BETRAuJWYy1U4hqz'); f = Inky::File.new('2zSX2El5QOatv87CNXxt')
79
+ # Inky.authorize!('AEqf74BETRAuJWYy1U4hqz'); f = Inky::File.from_url('https://www.filepicker.io/api/file/2zSX2El5QOatv87CNXxt')
80
+ # Inky.authorize!('AEqf74BETRAuJWYy1U4hqz'); f = Inky::File.from_file(File.open('my_file.txt'))
@@ -0,0 +1,3 @@
1
+ module Inky
2
+ VERSION = '0.0.2'
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Smudge
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ description: A ruby client for filepicker.io's REST API
84
+ email:
85
+ - nathan@ngriffith.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - inky.gemspec
95
+ - lib/inky.rb
96
+ - lib/inky/file.rb
97
+ - lib/inky/version.rb
98
+ homepage: ''
99
+ licenses:
100
+ - ''
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.2.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: A ruby client for filepicker.io's REST API
122
+ test_files: []
123
+ has_rdoc: