smartfile 0.1
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 +7 -0
- data/CHANGELOG.md +1 -0
- data/README.md +74 -0
- data/ROADMAP.md +9 -0
- data/lib/init.rb +1 -0
- data/lib/smartfile.rb +82 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18bcc55819ada207ddc3bc621a1a185e476d9c79
|
4
|
+
data.tar.gz: f0975b81b82bd630a42f3d1a07d111dec3c11aff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5f2eb5713c3045d416604131780b456dbe2c48dbaca0b6647f3b71c3a1a6112e3e107fee53eb2c3ec90afc6033a98ab03f2bfdc551cc930f40212643cc821c4
|
7
|
+
data.tar.gz: 98c92faa203395f58934f09e7c03c213cb14ef2794da5ee66e29c1a8114315153dd732840269e22229547b58d3072407263f433cf55fc685760bd3c59ac1c398
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3/22/14 1:12am - Initial Version
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# SmartFile
|
2
|
+
|
3
|
+
A ruby client wrapper for the [SmartFile](http://smartfile.com) file platform.
|
4
|
+
SmartFile has free developer accounts with 1 user, 100GB storage, and 200GB monthly transfer!
|
5
|
+
|
6
|
+
Works with Ruby 1.9 and likely 2.0 (Has not been tested)
|
7
|
+
This is an early version and the interface might change so use at your own risk.
|
8
|
+
As of version 0.1, only whoami and ping paths have been tested! I added some others to play around with for the next gem version.
|
9
|
+
|
10
|
+
## API Paths Currently Implemented
|
11
|
+
|
12
|
+
- Path - Info, as :path_info
|
13
|
+
- Path - Data, as :path_data
|
14
|
+
- Path - Search, as :path_search
|
15
|
+
- Ping, as :ping
|
16
|
+
- Whoami, as :whoami
|
17
|
+
- Session, as :session
|
18
|
+
|
19
|
+
## Setup:
|
20
|
+
|
21
|
+
Instructions assume you are using Rails, but Rails is not required.
|
22
|
+
|
23
|
+
Create the file config/smartfile.yml:
|
24
|
+
|
25
|
+
key: your smartfile apikey here
|
26
|
+
pass: your smartfile password here
|
27
|
+
|
28
|
+
Create the file config/initializers:
|
29
|
+
|
30
|
+
api_config_path = "#{Rails.root}/config/smartfile.yml"
|
31
|
+
if File.exists?(api_config_path)
|
32
|
+
SMARTFILE_CONFIG = YAML.load_file(api_config_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
## Usage:
|
36
|
+
|
37
|
+
call = SmartFile.new
|
38
|
+
params = {:attribute => "query"}
|
39
|
+
call.setup(:whoami, format = "json")
|
40
|
+
|
41
|
+
# regular get
|
42
|
+
result = call.get(params)
|
43
|
+
|
44
|
+
# regular post
|
45
|
+
result = call.post(params)
|
46
|
+
|
47
|
+
# get or post with full response object
|
48
|
+
result = call.get(params, true)
|
49
|
+
puts result
|
50
|
+
=> "#<Net::HTTPOK 200 OK readbody=true>"
|
51
|
+
puts result.body
|
52
|
+
'{"ping": "pong"}'
|
53
|
+
|
54
|
+
|
55
|
+
## Valid Return Formats:
|
56
|
+
- json
|
57
|
+
- json-p
|
58
|
+
- json-t
|
59
|
+
- html
|
60
|
+
- xhtml
|
61
|
+
- txt
|
62
|
+
- xml
|
63
|
+
|
64
|
+
## (Optional) Use [Nokogiri](http://nokogiri.org/) to parse XML formatted results:
|
65
|
+
|
66
|
+
doc = Nokogiri::XML(result.body)
|
67
|
+
|
68
|
+
Then, to search for nodes existing in the result body by XML node name:
|
69
|
+
|
70
|
+
full_node = doc.css('nodeName')
|
71
|
+
|
72
|
+
To get the value of a node:
|
73
|
+
|
74
|
+
attr = doc.search('attr').text
|
data/ROADMAP.md
ADDED
data/lib/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'smartfile'
|
data/lib/smartfile.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "net/https"
|
2
|
+
require "uri"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
|
6
|
+
class SmartFile
|
7
|
+
|
8
|
+
attr_accessor :key, :pass
|
9
|
+
attr_accessor :base_url, :service_path
|
10
|
+
attr_accessor :response, :json_response
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
@key = SMARTFILE_CONFIG['key']
|
14
|
+
@pass = SMARTFILE_CONFIG['pass']
|
15
|
+
@base_url = "https://app.smartfile.com/api/2"
|
16
|
+
@service_path = ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def full_url
|
20
|
+
@base_url + @service_path
|
21
|
+
end
|
22
|
+
|
23
|
+
# valid formats - [json] [json-p] [json-t] [html] [xhtml] [txt] [xml]
|
24
|
+
def setup(endpoint, format = "json")
|
25
|
+
case endpoint
|
26
|
+
when :path_info
|
27
|
+
@service_path = "/ping/?format=#{format}"
|
28
|
+
when :path_data
|
29
|
+
@service_path = "/whoami/?format=#{format}"
|
30
|
+
when :session
|
31
|
+
@service_path = "/session/?format=#{format}"
|
32
|
+
when :ping
|
33
|
+
@service_path = "/ping/?format=#{format}"
|
34
|
+
when :whoami
|
35
|
+
@service_path = "/whoami/?format=#{format}"
|
36
|
+
when :session
|
37
|
+
@service_path = "/session/?format=#{format}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(params = {}, full_response = false)
|
42
|
+
uri = URI.parse(full_url)
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = true
|
45
|
+
# VERIFY_NONE is not ideal for security, but its a risk I'm willing to take.
|
46
|
+
# For the paranoid if you want to add cert bundles to your server you can fix it:
|
47
|
+
# http://www.rubyinside.com/how-to-cure-nethttps-risky-default-https-behavior-4010.html
|
48
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
49
|
+
@request = Net::HTTP::Get.new(uri.request_uri)
|
50
|
+
@request.basic_auth(@key, @pass)
|
51
|
+
@request["User-Agent"] = "smartfile_rubygem_1.0"
|
52
|
+
@response = http.request(@request)
|
53
|
+
|
54
|
+
if full_response
|
55
|
+
return @response
|
56
|
+
else
|
57
|
+
return @response.body
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def post(params = {}, full_response = false)
|
62
|
+
uri = URI.parse(full_url)
|
63
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
64
|
+
http.use_ssl = true
|
65
|
+
# VERIFY_NONE is not ideal for security, but its a risk I'm willing to take.
|
66
|
+
# For the paranoid if you want to add cert bundles to your server you can fix it:
|
67
|
+
# http://www.rubyinside.com/how-to-cure-nethttps-risky-default-https-behavior-4010.html
|
68
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
69
|
+
@request = Net::HTTP::Post.new(uri.request_uri)
|
70
|
+
@request.basic_auth(@key, @pass)
|
71
|
+
@request.set_form_data(params)
|
72
|
+
@response = http.request(@request)
|
73
|
+
|
74
|
+
if full_response
|
75
|
+
return @response
|
76
|
+
else
|
77
|
+
return @response.body
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smartfile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan L. Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Easily use the SmartFile APIs within your ruby or rails project.
|
28
|
+
email:
|
29
|
+
- rjs6143@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/smartfile.rb
|
35
|
+
- lib/init.rb
|
36
|
+
- README.md
|
37
|
+
- ROADMAP.md
|
38
|
+
- CHANGELOG.md
|
39
|
+
homepage: http://ryanjohnson.mobi
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.3.6
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.0.3
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: SmartFile API Wrapper
|
62
|
+
test_files: []
|
63
|
+
has_rdoc:
|