xj 0.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/xj.rb +28 -0
- data/lib/xj/api.rb +21 -0
- data/lib/xj/spreadsheet.rb +27 -0
- data/lib/xj/version.rb +3 -0
- data/test/test.rb +8 -0
- data/xj.gemspec +26 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7344fc6a45ec7ca99ac6e0ad5bcae4d2721119a4
|
4
|
+
data.tar.gz: d897852c2c6b571d8f01f3af4a8921323d7a94f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94e5b338d202793ee5adc17a648a393ce220d8fb427a410d9f663f25ceb1c9a50c8c77c6390acfbea7673b5c372bcca347cbdb325933007d64e2f859f86b04a0
|
7
|
+
data.tar.gz: e6c3fc12bd455ea20d3de4e55c2cbc6541220ee1eda269d5aed702eaa76b22e0e1a796b2e3215b24de2466378fffa43650d1642296957b02350a3aa780977d6f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Arthur
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# XJ
|
2
|
+
|
3
|
+
> Read XLS into JSON.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'xj'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install xj
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Goes like this:
|
22
|
+
|
23
|
+
spreadsheet = XJ::Spreadsheet.new('./sample.xls')
|
24
|
+
spreadsheet.to_json
|
25
|
+
spreadsheet.to_hash
|
26
|
+
|
27
|
+
Or use the shortcut:
|
28
|
+
|
29
|
+
XJ.read('./sample.xls').to_json
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/xj.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# XJ - Read XLS into JSON.
|
2
|
+
# Version: 1.0
|
3
|
+
# Author: Arthur <arthur@corenzan.com>
|
4
|
+
# Site: https://github.com/haggen/xj-ruby
|
5
|
+
#
|
6
|
+
# Example 1:
|
7
|
+
# spreadsheet = XJ::Spreadsheet.new('./sample.xls')
|
8
|
+
# spreadsheet.to_json
|
9
|
+
# spreadsheet.to_hash
|
10
|
+
#
|
11
|
+
# Example 2:
|
12
|
+
# XJ.read('./sample.xls').to_json
|
13
|
+
#
|
14
|
+
require 'xj/version'
|
15
|
+
require 'xj/api'
|
16
|
+
require 'xj/spreadsheet'
|
17
|
+
|
18
|
+
module XJ
|
19
|
+
|
20
|
+
# Exception class
|
21
|
+
class XJException < StandardError
|
22
|
+
end
|
23
|
+
|
24
|
+
# Shortcut
|
25
|
+
def self.read(path)
|
26
|
+
Spreadsheet.new(path)
|
27
|
+
end
|
28
|
+
end
|
data/lib/xj/api.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'net/http/post/multipart'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module XJ
|
5
|
+
module API
|
6
|
+
def self.post(path)
|
7
|
+
uri = URI.parse('http://radiant-coast-1430.herokuapp.com')
|
8
|
+
|
9
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
10
|
+
|
11
|
+
http.read_timeout = 15
|
12
|
+
http.open_timeout = 15
|
13
|
+
|
14
|
+
file = UploadIO.new File.open(path), 'application/octet-stream'
|
15
|
+
|
16
|
+
request = Net::HTTP::Post::Multipart.new(uri.request_uri, :file => file)
|
17
|
+
|
18
|
+
response = http.request(request)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module XJ
|
4
|
+
class Spreadsheet
|
5
|
+
attr_accessor :response
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
@response = API.post(path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def error
|
12
|
+
status != 200 ? status : to_hash['error']
|
13
|
+
end
|
14
|
+
|
15
|
+
def status
|
16
|
+
@response.code.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json
|
20
|
+
@response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
JSON.parse(to_json)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/xj/version.rb
ADDED
data/test/test.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path('../lib/xj.rb')
|
2
|
+
|
3
|
+
spreadsheet = XJ.read File.expand_path('~/Desktop/i.xls')
|
4
|
+
|
5
|
+
puts "Response: #{spreadsheet.response}"
|
6
|
+
puts "Status: #{spreadsheet.status}"
|
7
|
+
puts "Error?: #{spreadsheet.error}"
|
8
|
+
puts "Body length: #{spreadsheet.to_json.length}"
|
data/xj.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'xj/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "xj"
|
9
|
+
spec.version = XJ::VERSION
|
10
|
+
spec.authors = ["Arthur"]
|
11
|
+
spec.email = ["arthur@corenzan.com"]
|
12
|
+
spec.description = %q{XJ is a web service that reads spreadsheets and outputs its data in JSON.}
|
13
|
+
spec.summary = %q{Read XLS into JSON.}
|
14
|
+
spec.homepage = "https://github.com/haggen/xj-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "multipart-post"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xj
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arthur
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multipart-post
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: XJ is a web service that reads spreadsheets and outputs its data in JSON.
|
56
|
+
email:
|
57
|
+
- arthur@corenzan.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/xj.rb
|
68
|
+
- lib/xj/api.rb
|
69
|
+
- lib/xj/spreadsheet.rb
|
70
|
+
- lib/xj/version.rb
|
71
|
+
- test/test.rb
|
72
|
+
- xj.gemspec
|
73
|
+
homepage: https://github.com/haggen/xj-ruby
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Read XLS into JSON.
|
97
|
+
test_files:
|
98
|
+
- test/test.rb
|