officepod 0.1.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 +20 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/offciepod +26 -0
- data/bin/setup +8 -0
- data/lib/officepod/authentication.rb +33 -0
- data/lib/officepod/bookmark.rb +11 -0
- data/lib/officepod/exception.rb +23 -0
- data/lib/officepod/file.rb +11 -0
- data/lib/officepod/room.rb +11 -0
- data/lib/officepod/storage.rb +30 -0
- data/lib/officepod/version.rb +3 -0
- data/lib/officepod.rb +76 -0
- data/officepod.gemspec +36 -0
- data/spec/officepod_spec.rb +53 -0
- data/spec/spec_helper.rb +2 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 443b1914c1d34c8059c083f841eb2576dceb3c73
|
4
|
+
data.tar.gz: 00791e57be5f8388de2a1e4f9c5f73269475bb50
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21e1cb7835abb6c5ce8fe5eb49632fa8ab15b89507488f2fb4a1e136735dbc58f457a489b45100e6861bb9df806bd5f6d610457a5a9190d49a5889f8b0e0feb5
|
7
|
+
data.tar.gz: 9d69b3896067714b261638f50f7af51b27df1a5f87f076f801a89448e1cefe6f99199db1594ccaed592c84624d4162598ec3423e1d572628df0d09b4c6dffabf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Yoochan Seo
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# [Officepod](https://github.com/seoyoochan/officepod/) [](https://travis-ci.org/seoyoochan/officepod)
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'officepod'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install officepod
|
18
|
+
|
19
|
+
## Requirements
|
20
|
+
|
21
|
+
* Ruby 2.2.4 or higher
|
22
|
+
* json
|
23
|
+
* HTTParty
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Help and Docs
|
30
|
+
|
31
|
+
* [Docs](docs/)
|
32
|
+
* supergnee@gmail.com
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
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).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
* Fork the project.
|
43
|
+
* Run `bundle`
|
44
|
+
* Run `bundle exec rake`
|
45
|
+
* Make your feature addition or bug fix.
|
46
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
47
|
+
* Run `bundle exec rake` (No, REALLY :))
|
48
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
|
49
|
+
* Send me a pull request. Bonus points for topic branches.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "officepod"
|
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
|
data/bin/offciepod
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
require "pp-colour"
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
6
|
+
|
7
|
+
require "officepod"
|
8
|
+
|
9
|
+
opts = {
|
10
|
+
command: nil
|
11
|
+
headers: {},
|
12
|
+
data: {}
|
13
|
+
}
|
14
|
+
|
15
|
+
OptionParser.new do |o|
|
16
|
+
o.banner = "USAGE: #{$PROGRAM_NAME} options"
|
17
|
+
o.on("--version", "Show Officepod version") do |ver|
|
18
|
+
puts "Version: #{Officepod::VERSION}"
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end.parse!
|
22
|
+
|
23
|
+
if ARGV.empty?
|
24
|
+
STDERR.puts "You need to provide options"
|
25
|
+
STDERR.puts "USAGE: #{$PROGRAM_NAME} [options]"
|
26
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Officepod
|
2
|
+
module Authentication
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def login
|
9
|
+
response = self.post("/server/request.php", @options)
|
10
|
+
result = JSON.parse(response.parsed_response)
|
11
|
+
cookie = get_cookie(response.headers["set-cookie"])
|
12
|
+
result["SID"] = cookie
|
13
|
+
result["storage_list"] = storage_auth_list(lang: "ko", cookie: cookie)
|
14
|
+
result.delete_if { |k,v| ["result", "resultcode", "message"].include? k }
|
15
|
+
result
|
16
|
+
end
|
17
|
+
|
18
|
+
def logout
|
19
|
+
response = self.delete("/server/request.php", @options)
|
20
|
+
response.parsed_response
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_cookie(cookie)
|
26
|
+
sid_pattern = /(?!SID=)[a-z0-9]+(?=\;)/
|
27
|
+
result = cookie.match sid_pattern
|
28
|
+
result.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Officepod
|
2
|
+
module Exception
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Exception raised when using undefined command
|
6
|
+
class UnsupportedCommand < Error;
|
7
|
+
def initialize(command)
|
8
|
+
msg = "#{command} command is unsupported!"
|
9
|
+
super(msg)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"Unsupported Command: #{command}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Exception raised when passing no command
|
18
|
+
class EmptyCommand < Error; end
|
19
|
+
|
20
|
+
# Exception raised when passing no body
|
21
|
+
class EmptyBody < Error; end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Officepod
|
2
|
+
module Storage
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def storage_auth_list(lang: nil, cookie: nil)
|
9
|
+
command = __method__.to_s
|
10
|
+
@options[:command] = command
|
11
|
+
@options[:body] = {
|
12
|
+
"command": command,
|
13
|
+
"lang": lang
|
14
|
+
}
|
15
|
+
@options[:headers]["Cookie"] = "SID=#{cookie}"
|
16
|
+
ipv4_pattern = /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/
|
17
|
+
response = self.post("/server/request.php", @options)
|
18
|
+
result = JSON.parse(response.parsed_response)
|
19
|
+
result["storagelist"].each do |e|
|
20
|
+
e["type"] = "FTP" if e["title"].include? "FTP"
|
21
|
+
e["type"] = "SMB" if e["title"].include? "SMB"
|
22
|
+
ip = e["filepath"].match ipv4_pattern
|
23
|
+
e["ip"]= ip.to_s
|
24
|
+
end
|
25
|
+
result["storagelist"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/officepod.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Officepod
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
base.class_eval do
|
5
|
+
include HTTParty
|
6
|
+
include Authentication
|
7
|
+
include Storage
|
8
|
+
include Bookmark
|
9
|
+
include File
|
10
|
+
include Room
|
11
|
+
|
12
|
+
base_uri "http://g4m.lalaworks.com"
|
13
|
+
|
14
|
+
@options = {
|
15
|
+
command: "",
|
16
|
+
headers: {
|
17
|
+
"User-Agent" => "Gate4Mobile",
|
18
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
19
|
+
"Accept" => "application/json",
|
20
|
+
"Cookie" => ""
|
21
|
+
},
|
22
|
+
body: {}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def officepod(options={command: "", body: "", cookie: ""})
|
29
|
+
@options[:command] = options[:command]
|
30
|
+
@options[:body] = options[:body]
|
31
|
+
@options[:headers]["Cookie"] = options[:cookie]
|
32
|
+
validates_command
|
33
|
+
send(options[:command])
|
34
|
+
end
|
35
|
+
|
36
|
+
def validates_command
|
37
|
+
if command_empty?
|
38
|
+
::Kernel.raise EmptyCommand.new
|
39
|
+
else
|
40
|
+
if unsupported_command?
|
41
|
+
::Kernel.raise UnsupportedCommand.new(@options[:command])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def validates_body
|
47
|
+
::Kernel.raise EmptyBody.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def unsupported_command?
|
51
|
+
!(self.class_methods.include? @options[:command].to_sym)
|
52
|
+
end
|
53
|
+
|
54
|
+
def command_empty?
|
55
|
+
@options[:command].empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
def body_empty?
|
59
|
+
@options[:body].empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def class_methods
|
63
|
+
self.methods - Object.methods
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
require "json"
|
70
|
+
require "httparty"
|
71
|
+
require "officepod/exception"
|
72
|
+
require "officepod/authentication"
|
73
|
+
require "officepod/storage"
|
74
|
+
require "officepod/bookmark"
|
75
|
+
require "officepod/file"
|
76
|
+
require "officepod/room"
|
data/officepod.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'officepod/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "officepod"
|
8
|
+
spec.version = Officepod::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Yoochan Seo"]
|
11
|
+
spec.email = ["supergnee@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Easy to communicate with Officepod server!"
|
14
|
+
spec.description = "Call to the original Officepod API server is hassle,
|
15
|
+
this gem makes your life a lot easier."
|
16
|
+
spec.homepage = "https://github.com/seoyoochan/officepod"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
# end
|
26
|
+
|
27
|
+
spec.required_ruby_version = ">= 2.2.4"
|
28
|
+
|
29
|
+
spec.add_dependency "json", "~> 1.8"
|
30
|
+
spec.add_dependency "httparty", "~> 0.13.7"
|
31
|
+
|
32
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
34
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ["lib"]
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Officepod do
|
4
|
+
before(:each) do
|
5
|
+
@klass = Class.new
|
6
|
+
@klass.instance_eval { include Officepod }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has base_uri from HTTParty" do
|
10
|
+
expect(@klass.respond_to?(:base_uri)).to eq true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has officepod method" do
|
14
|
+
expect(@klass.respond_to?(:offciepod)).not_to be nil
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when login" do
|
18
|
+
response = nil
|
19
|
+
|
20
|
+
it "should be success" do
|
21
|
+
options = {
|
22
|
+
command: "login",
|
23
|
+
headers: {
|
24
|
+
"User-Agent" => "Gate4Mobile",
|
25
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
26
|
+
"Accept" => "application/json"
|
27
|
+
},
|
28
|
+
body: {
|
29
|
+
'command': 'login',
|
30
|
+
'device_id': '0000',
|
31
|
+
'install_ver': '1.0.10',
|
32
|
+
'ip': '192.168.1.4',
|
33
|
+
'lang': 'ko',
|
34
|
+
'str': 'dGVzdHtHU310ZXN0'
|
35
|
+
},
|
36
|
+
cookie: ""
|
37
|
+
}
|
38
|
+
|
39
|
+
response = @klass.officepod(options)
|
40
|
+
|
41
|
+
expect(response.class).to eq Hash
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have storage list" do
|
45
|
+
expect(response["storage_list"].class).to eq Array
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: officepod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoochan Seo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.7
|
41
|
+
description: |-
|
42
|
+
Call to the original Officepod API server is hassle,
|
43
|
+
this gem makes your life a lot easier.
|
44
|
+
email:
|
45
|
+
- supergnee@gmail.com
|
46
|
+
executables:
|
47
|
+
- console
|
48
|
+
- offciepod
|
49
|
+
- setup
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- ".gitignore"
|
54
|
+
- ".rspec"
|
55
|
+
- ".travis.yml"
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/console
|
61
|
+
- bin/offciepod
|
62
|
+
- bin/setup
|
63
|
+
- lib/officepod.rb
|
64
|
+
- lib/officepod/authentication.rb
|
65
|
+
- lib/officepod/bookmark.rb
|
66
|
+
- lib/officepod/exception.rb
|
67
|
+
- lib/officepod/file.rb
|
68
|
+
- lib/officepod/room.rb
|
69
|
+
- lib/officepod/storage.rb
|
70
|
+
- lib/officepod/version.rb
|
71
|
+
- officepod.gemspec
|
72
|
+
- spec/officepod_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/seoyoochan/officepod
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.2.4
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Easy to communicate with Officepod server!
|
98
|
+
test_files:
|
99
|
+
- spec/officepod_spec.rb
|
100
|
+
- spec/spec_helper.rb
|