sharefile_connect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2854e6d977b443111a4302d4e140767adcc31f51
4
+ data.tar.gz: 46f1156230026391f189c1f354e7189134f9f751
5
+ SHA512:
6
+ metadata.gz: ce70f2a748da3d6b402409201fb1259e04a3d2d59f2bc9fbb4738b873df625471a8cae9b3d3229496f983818684b022eca1b55dca94567ac8e0d4251851251e6
7
+ data.tar.gz: fec1c11dac80359826044705b07c8469df1ea233c6d7435ee211f6d9b2798eed94656ac31390f053eabe283ebcb980ad95ab746bab14f37c932d08c21c82df7d
@@ -0,0 +1,98 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
11
+
12
+ ### JetBrains template
13
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion
14
+
15
+ *.iml
16
+
17
+ ## Directory-based project format:
18
+ .idea/
19
+ # if you remove the above rule, at least ignore the following:
20
+
21
+ # User-specific stuff:
22
+ # .idea/workspace.xml
23
+ # .idea/tasks.xml
24
+ # .idea/dictionaries
25
+
26
+ # Sensitive or high-churn files:
27
+ # .idea/dataSources.ids
28
+ # .idea/dataSources.xml
29
+ # .idea/sqlDataSources.xml
30
+ # .idea/dynamic.xml
31
+ # .idea/uiDesigner.xml
32
+
33
+ # Gradle:
34
+ # .idea/gradle.xml
35
+ # .idea/libraries
36
+
37
+ # Mongo Explorer plugin:
38
+ # .idea/mongoSettings.xml
39
+
40
+ ## File-based project format:
41
+ *.ipr
42
+ *.iws
43
+
44
+ ## Plugin-specific files:
45
+
46
+ # IntelliJ
47
+ /out/
48
+
49
+ # mpeltonen/sbt-idea plugin
50
+ .idea_modules/
51
+
52
+ # JIRA plugin
53
+ atlassian-ide-plugin.xml
54
+
55
+ # Crashlytics plugin (for Android Studio and IntelliJ)
56
+ com_crashlytics_export_strings.xml
57
+ crashlytics.properties
58
+ crashlytics-build.properties
59
+
60
+
61
+ ### Ruby template
62
+ *.gem
63
+ *.rbc
64
+ /.config
65
+ /coverage/
66
+ /InstalledFiles
67
+ /pkg/
68
+ /spec/reports/
69
+ /test/tmp/
70
+ /test/version_tmp/
71
+ /tmp/
72
+
73
+ ## Specific to RubyMotion:
74
+ .dat*
75
+ .repl_history
76
+ build/
77
+
78
+ ## Documentation cache and generated files:
79
+ /.yardoc/
80
+ /_yardoc/
81
+ /doc/
82
+ /rdoc/
83
+
84
+ ## Environment normalisation:
85
+ /.bundle/
86
+ /vendor/bundle
87
+ /lib/bundler/man/
88
+
89
+ # for a library or gem, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # Gemfile.lock
92
+ # .ruby-version
93
+ # .ruby-gemset
94
+
95
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
96
+ .rvmrc
97
+
98
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sharefile_connect.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 tubedude
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.
@@ -0,0 +1,60 @@
1
+ # SharefileConnect
2
+
3
+ This is a simple gem to allow any service to upload files to ShareFile as one single user.
4
+ Please refer to [ShareFile Api Documentation](https://api.sharefile.com/rest/docs/resource.aspx?name=Items) for more information.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'sharefile_connect'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install sharefile_connect
21
+
22
+ ## Usage
23
+
24
+ To retrieve a list of all Children Items:
25
+ ```ruby
26
+ sf = SharefileConnect::Data.new
27
+ sf.root
28
+ # => Returns a String that can be parsed to JSON
29
+ ```
30
+ To retreive an Item (File or Folder) by its path:
31
+ ```ruby
32
+ sf = SharefileConnect::Data.new
33
+ sf.items_by_path(["Parent Folder","Folder"])
34
+ ```
35
+ To upload a file to an specific folder:
36
+ ```ruby
37
+ sf = SharefileConnect::Data.new
38
+
39
+ # Find the id of a folder
40
+ folder_id = sf.items_by_path_id(['Folder1', 'Subfolder'])
41
+ file_path = '/some_file.pdf'
42
+ sf.upload_file(folder_id, file_path)
43
+ ```
44
+
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ 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).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sharefile_connect.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sharefile_connect"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+ require 'httparty'
4
+ require 'oauth2'
5
+ require 'net/https'
6
+ require 'uri'
7
+
8
+ Dir[File.dirname(__FILE__) + '/sharefile_connect/*.rb'].each do |file|
9
+ require file
10
+ end
11
+
12
+ module SharefileConnect
13
+ BASE_URI = "https://#{ENV['API_ENDPOINT_DOMAIN']}.sf-api.com/sf/v3"
14
+ end
15
+
@@ -0,0 +1,37 @@
1
+ module SharefileConnect
2
+ class Connection
3
+ attr_reader :token
4
+ include HTTParty
5
+ # base_uri "https://#{ENV['API_ENDPOINT_DOMAIN']}.sf-api.com"
6
+
7
+ def initialize
8
+ response = HTTParty.post(authentication_uri, authentication_content)
9
+ @token = JSON.parse response.body
10
+ end
11
+
12
+ def hostname
13
+ "#{ENV['API_ENDPOINT_DOMAIN']}.sf-api.com"
14
+ end
15
+
16
+ def authentication_uri
17
+ "https://#{hostname}/oauth/token"
18
+ # "/oauth/token"
19
+ end
20
+
21
+ def authentication_content
22
+ {
23
+ :body => {
24
+ "grant_type" => "password",
25
+ "client_id" => ENV['SHAREFILE_KEY'],
26
+ "client_secret" => ENV['SHAREFILE_SECRET'],
27
+ "username" => ENV['SHAREFILE_USER_NAME'],
28
+ "password" => ENV['SHAREFILE_USER_PASS']
29
+ },
30
+ :headers => {
31
+ "Content-Type" => "application/x-www-form-urlencoded"
32
+ }
33
+ }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,119 @@
1
+ module SharefileConnect
2
+ class Data
3
+ include HTTParty
4
+
5
+ def root(id = nil)
6
+ parse_get("/Items(#{id || 'allshared'})?$expand=Children&$select=Id,Name,Children/Id,Children/Name").body
7
+ end
8
+
9
+ def folder_access_info(id)
10
+ parse_get("/Items(#{id})/Info").body
11
+ end
12
+
13
+ def item(id)
14
+ get("/Items(#{id})")
15
+ end
16
+
17
+ # def create_folder parent_id, name, description = ''
18
+ # unless folder_exists?(name, parent_id)
19
+ # body = {
20
+ # "Name" => name,
21
+ # "Description" => description || name
22
+ # }
23
+ # HTTParty.post(full("Items#{parent_id}/Folder?overwrite=false&passthrough=false"), { body: body.to_json, headers: authorization_header})
24
+ # else
25
+ # item(folder_in_parent(name, parent_id)['Id'])
26
+ # end
27
+ # end
28
+
29
+ def folder_exists?(name, parent_id = nil)
30
+ folder_in_parent(name, parent_id).any?
31
+ end
32
+
33
+ def folder_in_parent(name, parent_id)
34
+ JSON.parse(root(parent_id))['Children'].select { |f| f['Name'] == name }
35
+ end
36
+
37
+ def items_by_path(paths)
38
+ parse_get("/Items/ByPath?path=/#{paths.join('/')}/&$expand=Children&$select=Id,Name,Children/Id,Children/Name")
39
+ end
40
+
41
+ def items_by_path_id(paths)
42
+ r = items_by_path(paths).response
43
+ JSON.parse(r.body)['Id'] if r.kind_of?(Net::HTTPOK)
44
+ end
45
+
46
+ def upload_file folder_id, file_path
47
+ path = "/Items(#{folder_id})/Upload"
48
+ response = HTTParty.get(full(path), headers: authorization_header)
49
+ upload_config = JSON.parse response.body
50
+ multipart_form_post upload_config['ChunkUri'], file_path
51
+ # HTTMultiParty.post(upload_config["ChunkUri"], body: { file1: File.new(file_path) } )
52
+ # File.open(file_path) do |transfile|
53
+ # # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: File.read(transfile) })
54
+ # # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: UploadIO.new(transfile, "multipart/formdata", File.basename(file_path)) })
55
+ # # HTTMultiParty.post(upload_config["ChunkUri"], query: { file1: UploadIO.new(File.open(file_path), "multipart/formdata") })
56
+ # end
57
+ end
58
+
59
+ def zones
60
+ get("/Zones")
61
+ end
62
+
63
+ def zone_id
64
+ JSON.parse(zones.response.body)['value'].map { |x| x['Id'] if x['ZoneType'] == 'CitrixManaged' }.compact.first
65
+ end
66
+
67
+ private
68
+
69
+ def multipart_form_post url, file_path
70
+ newline = "\r\n"
71
+ filename = File.basename(file_path)
72
+ boundary = "----------#{Time.now.nsec}"
73
+
74
+ uri = URI.parse(url)
75
+
76
+ post_body = []
77
+ post_body << "--#{boundary}#{newline}"
78
+ post_body << "Content-Disposition: form-data; name=\"File1\"; filename=\"#{filename}\"#{newline}"
79
+ post_body << "Content-Type: application/octet-stream#{newline}"
80
+ post_body << "#{newline}"
81
+ post_body << File.read(file_path)
82
+ post_body << "#{newline}--#{boundary}--#{newline}"
83
+
84
+ request = Net::HTTP::Post.new(uri.request_uri)
85
+ request.body = post_body.join
86
+ request['Content-Type'] = "multipart/form-data, boundary=#{boundary}"
87
+ request['Content-Length'] = request.body().length
88
+
89
+ http = Net::HTTP.new uri.host, uri.port
90
+ http.use_ssl = true
91
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
92
+
93
+ http.request request
94
+ end
95
+
96
+
97
+ def connection
98
+ @connection ||= SharefileConnect::Connection.new.token
99
+ end
100
+
101
+ def full path
102
+ "#{BASE_URI}#{path}"
103
+ end
104
+
105
+ def parse_get(path)
106
+ get(path)
107
+ end
108
+
109
+ def get(path)
110
+ HTTParty.get(full(path), headers: authorization_header)
111
+ end
112
+
113
+ def authorization_header
114
+ return { "Authorization" => "Bearer #{connection['access_token']}" }
115
+ end
116
+
117
+
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module SharefileConnect
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sharefile_connect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sharefile_connect"
8
+ spec.version = SharefileConnect::VERSION
9
+ spec.authors = ["tubedude"]
10
+ spec.email = ["rtrevisan@gmail.com"]
11
+
12
+ spec.summary = %q{Another Sharefile Ruby Wrapper}
13
+ spec.description = %q{This is a simple gem to allow any service to upload files to ShareFile as one single user. Please refer to ShareFile Api Documentation for more information.}
14
+ spec.homepage = "https://github.com/tubedude/sharefile_connect"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'httparty', '~>0.13'
23
+ # spec.add_dependency 'httmultiparty'
24
+ # spec.add_dependency 'oauth2'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", '~> 3.3'
29
+ spec.add_development_dependency "dotenv", '~> 2.0'
30
+ # spec.add_development_dependency "webmock"
31
+ # spec.add_development_dependency "vcr"
32
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sharefile_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tubedude
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-09 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: This is a simple gem to allow any service to upload files to ShareFile
84
+ as one single user. Please refer to ShareFile Api Documentation for more information.
85
+ email:
86
+ - rtrevisan@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".idea/.name"
93
+ - ".idea/misc.xml"
94
+ - ".idea/modules.xml"
95
+ - ".idea/sharefile_connect.iml"
96
+ - ".idea/vcs.xml"
97
+ - ".idea/workspace.xml"
98
+ - ".rspec"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
105
+ - bin/setup
106
+ - lib/sharefile_connect.rb
107
+ - lib/sharefile_connect/connection.rb
108
+ - lib/sharefile_connect/data.rb
109
+ - lib/sharefile_connect/version.rb
110
+ - sharefile_connect.gemspec
111
+ homepage: https://github.com/tubedude/sharefile_connect
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.8
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Another Sharefile Ruby Wrapper
135
+ test_files: []