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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7351d432c54e9e0d80e2942962357677697724d0
4
- data.tar.gz: 8da4d74c030d467fa002b7b0e76450776d04637d
3
+ metadata.gz: d755d4e4221e28c27bb61999216a64e48d8735ee
4
+ data.tar.gz: aff97b6d7cef96928fdf93fcfee93b95ba9dec87
5
5
  SHA512:
6
- metadata.gz: df6fdefdddf22474d52f786b736680d14af93478b927fba5c244e336e6583824811d6d9b8eccb82b397ee7f4e95d6dbf4ebd3b3ecb61605333ff5788058295fb
7
- data.tar.gz: 7fa1f4c1a7d7b518748b0da04963ab9874a58e3c1c6ddacc1b5d638b9fa27df47158fbce377e78397c80def3b9149fd90be3d51345b12a4bde28b665fd63ee08
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
- response = officepod({command: "login", body: params[:user]})
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
- response = officepod({command: "logout"})
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
- base.class_eval do
18
- def initialize
19
- @END_POINT = "/server/request.php"
20
-
21
- @options = {
22
- command: "",
23
- headers: {
24
- "User-Agent" => "Gate4Mobile",
25
- "Content-Type" => "application/x-www-form-urlencoded",
26
- "Accept" => "application/json",
27
- "Cookie" => ""
28
- },
29
- body: {}
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
- end
32
- end
28
+ }
33
29
 
34
- end
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
- private
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
- def get_cookie(cookie)
27
- sid_pattern = /(?!SID=)[a-z0-9]+(?=\;)/
28
- result = cookie.match sid_pattern
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
@@ -1,11 +1,4 @@
1
1
  module Officepod
2
2
  module Bookmark
3
- def self.included(base)
4
- base.send :include, InstanceMethods
5
- end
6
-
7
- module InstanceMethods
8
- end
9
-
10
3
  end
11
4
  end
@@ -1,11 +1,4 @@
1
1
  module Officepod
2
2
  module File
3
- def self.included(base)
4
- base.send :include, InstanceMethods
5
- end
6
-
7
- module InstanceMethods
8
- end
9
-
10
3
  end
11
4
  end
@@ -1,33 +1,31 @@
1
1
  module Officepod
2
2
  module Helper
3
+
3
4
  def validates_command
4
5
  if command_empty?
5
- ::Kernel.raise EmptyCommand.new
6
+ raise Officepod::Exception::EmptyCommand.new
6
7
  else
7
8
  if unsupported_command?
8
- ::Kernel.raise UnsupportedCommand.new(@options[:command])
9
+ raise Officepod::Exception::UnsupportedCommand.new(@command)
9
10
  end
10
11
  end
11
12
  end
12
13
 
13
14
  def validates_body
14
- ::Kernel.raise EmptyBody.new if body_empty?
15
+ raise Officepod::Exception::EmptyBody.new if body_empty?
15
16
  end
16
17
 
17
18
  def unsupported_command?
18
- !(self.class_methods.include? @options[:command].to_sym)
19
+ !(self.class.instance_methods.include?(@command.to_sym))
19
20
  end
20
21
 
21
22
  def command_empty?
22
- @options[:command].empty?
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
@@ -1,11 +1,4 @@
1
1
  module Officepod
2
2
  module Room
3
- def self.included(base)
4
- base.send :include, InstanceMethods
5
- end
6
-
7
- module InstanceMethods
8
- end
9
-
10
3
  end
11
4
  end
@@ -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
- module InstanceMethods
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.class.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"]
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
@@ -1,3 +1,3 @@
1
1
  module Officepod
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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 { include Officepod }
7
- @instance = @klass.new
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
- it "should return hash resonse" do
36
- options = {
37
- command: "login",
38
- body: {
10
+ def login
11
+ body = {
39
12
  'command': 'login',
40
- 'device_id': '0000',
41
- 'install_ver': '1.0.10',
42
- 'ip': '192.168.1.4',
13
+ 'device_id': '',
14
+ 'install_ver': '',
15
+ 'ip': 'localhost:3000',
43
16
  'lang': 'ko',
44
17
  'str': 'dGVzdHtHU310ZXN0'
45
18
  }
46
- }
47
19
 
48
- response = @instance.officepod(options)
49
-
50
- expect(response.class).to eq Hash
51
- end
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
- it "should have storage list as array" do
54
- expect(response["storage_list"].class).to eq Array
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.6
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-21 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json