officepod 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/officepod.rb +37 -46
- data/lib/officepod/authentication.rb +18 -26
- data/lib/officepod/bookmark.rb +0 -7
- data/lib/officepod/file.rb +0 -7
- data/lib/officepod/helper.rb +6 -8
- data/lib/officepod/room.rb +0 -7
- data/lib/officepod/storage.rb +16 -23
- data/lib/officepod/version.rb +1 -1
- data/spec/officepod_spec.rb +18 -46
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d755d4e4221e28c27bb61999216a64e48d8735ee
|
4
|
+
data.tar.gz: aff97b6d7cef96928fdf93fcfee93b95ba9dec87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c078f037d370d3ff5a82328d1fddbcd7c8651c44f6ce61b35c7f89fe93c8e2d6c948314a4946f91028dbee14cd716a12fc3eee6a7dc0024fa14ce5bf42e23117
|
7
|
+
data.tar.gz: ce57682e0a5d19938b7836ffcb9883eb6e7ee5c7a6ef545b6c905094e1a66658adec226a2d7e5f78b49abd3bf7b1be7165a2ea4e4810d9cc298c2148345c53f9
|
data/README.md
CHANGED
@@ -34,14 +34,24 @@ class Api::UsersController < ApplicationController
|
|
34
34
|
before_filter :user_params
|
35
35
|
|
36
36
|
def login
|
37
|
-
|
37
|
+
body = {
|
38
|
+
'command': 'login',
|
39
|
+
'device_id': '',
|
40
|
+
'install_ver': '',
|
41
|
+
'ip': 'localhost:3000',
|
42
|
+
'lang': 'ko',
|
43
|
+
'str': 'dGVzdHtHU310ZXN0'
|
44
|
+
}
|
45
|
+
o = Officepod::Base.new("login", body)
|
46
|
+
response = o.operate
|
38
47
|
respond_to do |format|
|
39
48
|
format.json { render json: response, status: 200 }
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
52
|
def logout
|
44
|
-
|
53
|
+
o = Officepod::Base.new("logout", body)
|
54
|
+
response = o.operate
|
45
55
|
respond_to do |format|
|
46
56
|
format.json { render json: response, status: 200 }
|
47
57
|
end
|
data/lib/officepod.rb
CHANGED
@@ -1,56 +1,47 @@
|
|
1
|
+
require "json"
|
2
|
+
require "httparty"
|
3
|
+
require "officepod/helper"
|
4
|
+
require "officepod/exception"
|
5
|
+
require "officepod/authentication"
|
6
|
+
require "officepod/storage"
|
7
|
+
require "officepod/bookmark"
|
8
|
+
require "officepod/file"
|
9
|
+
require "officepod/room"
|
10
|
+
|
1
11
|
module Officepod
|
2
|
-
def self.included(base)
|
3
|
-
base.send :include, InstanceMethods
|
4
|
-
|
5
|
-
base.instance_eval do
|
6
|
-
include HTTParty
|
7
|
-
include Authentication
|
8
|
-
include Storage
|
9
|
-
include Bookmark
|
10
|
-
include File
|
11
|
-
include Room
|
12
|
-
include Helper
|
13
|
-
|
14
|
-
base_uri "http://g4m.lalaworks.com"
|
15
|
-
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
13
|
+
class Base
|
14
|
+
include HTTParty
|
15
|
+
include Authentication
|
16
|
+
include Helper
|
17
|
+
include Storage
|
18
|
+
|
19
|
+
base_uri "http://g4m.lalaworks.com"
|
20
|
+
|
21
|
+
def initialize(command=nil, body={}, cookie="")
|
22
|
+
options = {
|
23
|
+
headers: {
|
24
|
+
"User-Agent" => "Gate4Mobile",
|
25
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
26
|
+
"Accept" => "application/json"
|
30
27
|
}
|
31
|
-
|
32
|
-
end
|
28
|
+
}
|
33
29
|
|
34
|
-
|
30
|
+
end_point = "/server/request.php"
|
31
|
+
|
32
|
+
self.instance_variable_set("@options", options)
|
33
|
+
self.instance_variable_set("@end_point", end_point)
|
34
|
+
self.instance_variable_set("@command", command)
|
35
|
+
@options[:body] = body unless body.empty?
|
36
|
+
@options[:headers]["Cookie"] = cookie unless cookie.empty?
|
35
37
|
|
36
|
-
module InstanceMethods
|
37
|
-
def officepod(options={command: "", body: "", cookie: ""})
|
38
|
-
@options[:command] = options[:command]
|
39
|
-
@options[:body] = options[:body]
|
40
|
-
@options[:headers]["Cookie"] ||= options[:cookie]
|
41
38
|
validates_command
|
42
|
-
send(@options[:command])
|
43
39
|
end
|
40
|
+
|
41
|
+
def operate
|
42
|
+
send(@command)
|
43
|
+
end
|
44
|
+
|
44
45
|
end
|
45
46
|
|
46
47
|
end
|
47
|
-
|
48
|
-
require "json"
|
49
|
-
require "httparty"
|
50
|
-
require "officepod/helper"
|
51
|
-
require "officepod/exception"
|
52
|
-
require "officepod/authentication"
|
53
|
-
require "officepod/storage"
|
54
|
-
require "officepod/bookmark"
|
55
|
-
require "officepod/file"
|
56
|
-
require "officepod/room"
|
@@ -1,34 +1,26 @@
|
|
1
1
|
module Officepod
|
2
2
|
module Authentication
|
3
|
-
def self.included(base)
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
def login
|
9
|
-
validates_body
|
10
|
-
response = self.class.post(@END_POINT, @options)
|
11
|
-
result = JSON.parse(response.parsed_response)
|
12
|
-
cookie = get_cookie(response.headers["set-cookie"])
|
13
|
-
result["SID"] = cookie
|
14
|
-
result["storage_list"] = storage_auth_list(lang: "ko", cookie: cookie)
|
15
|
-
result.delete_if { |k,v| ["result", "resultcode", "message"].include? k }
|
16
|
-
result
|
17
|
-
end
|
18
|
-
|
19
|
-
def logout
|
20
|
-
response = self.class.delete(@END_POINT, @options)
|
21
|
-
response.parsed_response
|
22
|
-
end
|
23
3
|
|
24
|
-
|
4
|
+
def login
|
5
|
+
validates_body
|
6
|
+
response = self.class.post(@end_point, @options)
|
7
|
+
result = JSON.parse(response.parsed_response)
|
8
|
+
cookie = get_cookie(response.headers["set-cookie"])
|
9
|
+
result["SID"] = cookie
|
10
|
+
result["storage_list"] = storage_auth_list(lang: "ko", cookie: cookie)
|
11
|
+
result.delete_if { |k,v| ["result", "resultcode", "message"].include? k }
|
12
|
+
result
|
13
|
+
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
result.to_s
|
30
|
-
end
|
15
|
+
def logout
|
16
|
+
response = self.class.delete(@end_point, @options)
|
17
|
+
response.parsed_response
|
31
18
|
end
|
32
19
|
|
20
|
+
def get_cookie(cookie)
|
21
|
+
sid_pattern = /(?!SID=)[a-z0-9]+(?=\;)/
|
22
|
+
result = cookie.match sid_pattern
|
23
|
+
result.to_s
|
24
|
+
end
|
33
25
|
end
|
34
26
|
end
|
data/lib/officepod/bookmark.rb
CHANGED
data/lib/officepod/file.rb
CHANGED
data/lib/officepod/helper.rb
CHANGED
@@ -1,33 +1,31 @@
|
|
1
1
|
module Officepod
|
2
2
|
module Helper
|
3
|
+
|
3
4
|
def validates_command
|
4
5
|
if command_empty?
|
5
|
-
|
6
|
+
raise Officepod::Exception::EmptyCommand.new
|
6
7
|
else
|
7
8
|
if unsupported_command?
|
8
|
-
|
9
|
+
raise Officepod::Exception::UnsupportedCommand.new(@command)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def validates_body
|
14
|
-
|
15
|
+
raise Officepod::Exception::EmptyBody.new if body_empty?
|
15
16
|
end
|
16
17
|
|
17
18
|
def unsupported_command?
|
18
|
-
!(self.
|
19
|
+
!(self.class.instance_methods.include?(@command.to_sym))
|
19
20
|
end
|
20
21
|
|
21
22
|
def command_empty?
|
22
|
-
@
|
23
|
+
@command.empty?
|
23
24
|
end
|
24
25
|
|
25
26
|
def body_empty?
|
26
27
|
@options[:body].empty?
|
27
28
|
end
|
28
29
|
|
29
|
-
def class_methods
|
30
|
-
self.methods - Object.methods
|
31
|
-
end
|
32
30
|
end
|
33
31
|
end
|
data/lib/officepod/room.rb
CHANGED
data/lib/officepod/storage.rb
CHANGED
@@ -1,30 +1,23 @@
|
|
1
1
|
module Officepod
|
2
2
|
module Storage
|
3
|
-
def self.included(base)
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ip = e["filepath"].match ipv4_pattern
|
23
|
-
e["ip"]= ip.to_s
|
24
|
-
end
|
25
|
-
result["storagelist"]
|
4
|
+
def storage_auth_list(lang: nil, cookie: nil)
|
5
|
+
command = __method__.to_s
|
6
|
+
@options[:body] = {
|
7
|
+
"command": command,
|
8
|
+
"lang": lang
|
9
|
+
}
|
10
|
+
@options[:headers]["Cookie"] = "SID=#{cookie}"
|
11
|
+
ipv4_pattern = /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/
|
12
|
+
response = self.class.post(@end_point, @options)
|
13
|
+
result = JSON.parse(response.parsed_response)
|
14
|
+
result["storagelist"].each do |e|
|
15
|
+
e["type"] = "FTP" if e["title"].include? "FTP"
|
16
|
+
e["type"] = "SMB" if e["title"].include? "SMB"
|
17
|
+
ip = e["filepath"].match ipv4_pattern
|
18
|
+
e["ip"]= ip.to_s
|
26
19
|
end
|
20
|
+
result["storagelist"]
|
27
21
|
end
|
28
|
-
|
29
22
|
end
|
30
23
|
end
|
data/lib/officepod/version.rb
CHANGED
data/spec/officepod_spec.rb
CHANGED
@@ -1,62 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
describe Officepod do
|
4
5
|
before(:each) do
|
5
6
|
@klass = Class.new
|
6
|
-
@klass.class_eval {
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
context "Officepod class" do
|
11
|
-
it "has base_uri as a class method" do
|
12
|
-
expect(@klass.respond_to?(:base_uri)).to eq true
|
13
|
-
end
|
14
|
-
|
15
|
-
it "has officepod as an instance method" do
|
16
|
-
expect(@klass.instance_methods.include?(:officepod)).to eq true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "has login as an instance method" do
|
20
|
-
expect(@klass.instance_methods.include?(:login)).to eq true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "has @options instance variable" do
|
24
|
-
expect(@instance.instance_variable_defined?(:@options)).to eq true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "has @END_POINT instance variable" do
|
28
|
-
expect(@instance.instance_variable_defined?(:@END_POINT)).to eq true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when login" do
|
33
|
-
response = nil
|
7
|
+
@klass.class_eval {
|
8
|
+
include Officepod
|
34
9
|
|
35
|
-
|
36
|
-
|
37
|
-
command: "login",
|
38
|
-
body: {
|
10
|
+
def login
|
11
|
+
body = {
|
39
12
|
'command': 'login',
|
40
|
-
'device_id': '
|
41
|
-
'install_ver': '
|
42
|
-
'ip': '
|
13
|
+
'device_id': '',
|
14
|
+
'install_ver': '',
|
15
|
+
'ip': 'localhost:3000',
|
43
16
|
'lang': 'ko',
|
44
17
|
'str': 'dGVzdHtHU310ZXN0'
|
45
18
|
}
|
46
|
-
}
|
47
19
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
20
|
+
o = Officepod::Base.new("login", body)
|
21
|
+
o.operate
|
22
|
+
end
|
23
|
+
}
|
24
|
+
@instance = @klass.new
|
25
|
+
@response = @instance.login
|
26
|
+
end
|
52
27
|
|
53
|
-
|
54
|
-
|
28
|
+
context "login response" do
|
29
|
+
it "should have storage list" do
|
30
|
+
expect(@response["storage_list"]).not_to eq nil
|
55
31
|
end
|
56
|
-
|
57
32
|
end
|
58
33
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: officepod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoochan Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|