under-os 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -2
- data/README.md +1 -1
- data/Rakefile +2 -4
- data/lib/under-os.rb +3 -8
- data/under-os.gemspec +6 -2
- metadata +47 -191
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/under-os.css +0 -115
- data/lib/under_os.rb +0 -41
- data/lib/under_os/app.rb +0 -33
- data/lib/under_os/color.rb +0 -184
- data/lib/under_os/config.rb +0 -33
- data/lib/under_os/core/array.rb +0 -5
- data/lib/under_os/core/hash.rb +0 -10
- data/lib/under_os/core/json.rb +0 -19
- data/lib/under_os/core/kernel.rb +0 -16
- data/lib/under_os/core/numeric.rb +0 -23
- data/lib/under_os/core/object.rb +0 -9
- data/lib/under_os/core/string.rb +0 -80
- data/lib/under_os/delegate.rb +0 -10
- data/lib/under_os/events.rb +0 -85
- data/lib/under_os/file.rb +0 -110
- data/lib/under_os/history.rb +0 -53
- data/lib/under_os/http.rb +0 -31
- data/lib/under_os/http/cookies.rb +0 -30
- data/lib/under_os/http/receiver.rb +0 -44
- data/lib/under_os/http/request.rb +0 -106
- data/lib/under_os/http/response.rb +0 -28
- data/lib/under_os/http/session.rb +0 -49
- data/lib/under_os/page.rb +0 -169
- data/lib/under_os/page/builder.rb +0 -96
- data/lib/under_os/page/layout.rb +0 -43
- data/lib/under_os/page/matcher.rb +0 -128
- data/lib/under_os/page/stylesheet.rb +0 -67
- data/lib/under_os/parser.rb +0 -24
- data/lib/under_os/parser/css.rb +0 -37
- data/lib/under_os/parser/html.rb +0 -97
- data/lib/under_os/point.rb +0 -47
- data/lib/under_os/screen.rb +0 -9
- data/lib/under_os/timer.rb +0 -65
- data/lib/under_os/ui.rb +0 -3
- data/lib/under_os/ui/alert.rb +0 -52
- data/lib/under_os/ui/button.rb +0 -42
- data/lib/under_os/ui/collection.rb +0 -65
- data/lib/under_os/ui/collection/cell.rb +0 -21
- data/lib/under_os/ui/collection/delegate.rb +0 -70
- data/lib/under_os/ui/collection/item.rb +0 -32
- data/lib/under_os/ui/collection/layout.rb +0 -43
- data/lib/under_os/ui/collection/styles.rb +0 -15
- data/lib/under_os/ui/div.rb +0 -3
- data/lib/under_os/ui/form.rb +0 -60
- data/lib/under_os/ui/icon.rb +0 -61
- data/lib/under_os/ui/icon/awesome.rb +0 -376
- data/lib/under_os/ui/icon/engine.rb +0 -10
- data/lib/under_os/ui/image.rb +0 -31
- data/lib/under_os/ui/input.rb +0 -140
- data/lib/under_os/ui/label.rb +0 -21
- data/lib/under_os/ui/locker.rb +0 -42
- data/lib/under_os/ui/navbar.rb +0 -123
- data/lib/under_os/ui/progress.rb +0 -17
- data/lib/under_os/ui/scroll.rb +0 -41
- data/lib/under_os/ui/select.rb +0 -95
- data/lib/under_os/ui/sidebar.rb +0 -45
- data/lib/under_os/ui/slider.rb +0 -37
- data/lib/under_os/ui/spinner.rb +0 -23
- data/lib/under_os/ui/style.rb +0 -21
- data/lib/under_os/ui/style/fonts.rb +0 -54
- data/lib/under_os/ui/style/margins.rb +0 -164
- data/lib/under_os/ui/style/outlining.rb +0 -170
- data/lib/under_os/ui/style/positioning.rb +0 -169
- data/lib/under_os/ui/switch.rb +0 -26
- data/lib/under_os/ui/textarea.rb +0 -19
- data/lib/under_os/ui/utils/animation.rb +0 -99
- data/lib/under_os/ui/utils/commons.rb +0 -70
- data/lib/under_os/ui/utils/dimensions.rb +0 -37
- data/lib/under_os/ui/utils/events.rb +0 -170
- data/lib/under_os/ui/utils/manipulation.rb +0 -44
- data/lib/under_os/ui/utils/position.rb +0 -21
- data/lib/under_os/ui/utils/size.rb +0 -21
- data/lib/under_os/ui/utils/styles.rb +0 -89
- data/lib/under_os/ui/utils/traversing.rb +0 -44
- data/lib/under_os/ui/utils/wrap.rb +0 -77
- data/lib/under_os/ui/view.rb +0 -31
- data/resources/test.png +0 -0
- data/spec/assets/app.css +0 -13
- data/spec/assets/test.css +0 -7
- data/spec/assets/test.html +0 -3
- data/spec/assets/test_page.rb +0 -2
- data/spec/lib/core/hash_spec.rb +0 -19
- data/spec/lib/core/json_spec.rb +0 -32
- data/spec/lib/core/numeric_spec.rb +0 -37
- data/spec/lib/core/string_spec.rb +0 -121
- data/spec/lib/under_os/color_spec.rb +0 -133
- data/spec/lib/under_os/events_spec.rb +0 -71
- data/spec/lib/under_os/file_spec.rb +0 -98
- data/spec/lib/under_os/http/cookies_spec.rb +0 -13
- data/spec/lib/under_os/http/request_spec.rb +0 -44
- data/spec/lib/under_os/http_spec.rb +0 -20
- data/spec/lib/under_os/page/builder_spec.rb +0 -128
- data/spec/lib/under_os/page/layout_spec.rb +0 -18
- data/spec/lib/under_os/page/matcher_spec.rb +0 -260
- data/spec/lib/under_os/page/stylesheet_spec.rb +0 -83
- data/spec/lib/under_os/page_spec.rb +0 -5
- data/spec/lib/under_os/parser/css_spec.rb +0 -77
- data/spec/lib/under_os/parser/html_spec.rb +0 -152
- data/spec/lib/under_os/parser_spec.rb +0 -16
- data/spec/lib/under_os/point_spec.rb +0 -54
- data/spec/lib/under_os/screen_spec.rb +0 -11
- data/spec/lib/under_os/timer_spec.rb +0 -93
- data/spec/lib/under_os/ui/button_spec.rb +0 -50
- data/spec/lib/under_os/ui/collection_spec.rb +0 -19
- data/spec/lib/under_os/ui/div_spec.rb +0 -24
- data/spec/lib/under_os/ui/form_spec.rb +0 -156
- data/spec/lib/under_os/ui/icon_spec.rb +0 -57
- data/spec/lib/under_os/ui/image_spec.rb +0 -39
- data/spec/lib/under_os/ui/input_spec.rb +0 -109
- data/spec/lib/under_os/ui/label_spec.rb +0 -22
- data/spec/lib/under_os/ui/locker_spec.rb +0 -31
- data/spec/lib/under_os/ui/progress_spec.rb +0 -31
- data/spec/lib/under_os/ui/scroll_spec.rb +0 -40
- data/spec/lib/under_os/ui/select_spec.rb +0 -135
- data/spec/lib/under_os/ui/sidebar_spec.rb +0 -35
- data/spec/lib/under_os/ui/slider_spec.rb +0 -69
- data/spec/lib/under_os/ui/spinner_spec.rb +0 -57
- data/spec/lib/under_os/ui/style/fonts_spec.rb +0 -73
- data/spec/lib/under_os/ui/style/margins_spec.rb +0 -106
- data/spec/lib/under_os/ui/style/outlining_spec.rb +0 -101
- data/spec/lib/under_os/ui/style/positioning_spec.rb +0 -69
- data/spec/lib/under_os/ui/style_spec.rb +0 -19
- data/spec/lib/under_os/ui/switch_spec.rb +0 -60
- data/spec/lib/under_os/ui/textarea_spec.rb +0 -34
- data/spec/lib/under_os/ui/utils/commons_spec.rb +0 -81
- data/spec/lib/under_os/ui/utils/events_spec.rb +0 -87
- data/spec/lib/under_os/ui/utils/manipulation_spec.rb +0 -130
- data/spec/lib/under_os/ui/utils/styles_spec.rb +0 -140
- data/spec/lib/under_os/ui/utils/traversing_spec.rb +0 -124
- data/spec/lib/under_os/ui/utils/wrap_spec.rb +0 -69
- data/spec/lib/under_os/ui/view_spec.rb +0 -39
data/lib/under_os/delegate.rb
DELETED
data/lib/under_os/events.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# A little events handling concern
|
3
|
-
#
|
4
|
-
module UnderOs::Events
|
5
|
-
|
6
|
-
def on(event, *args, &block)
|
7
|
-
Listeners.add(self, event, *args, block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def off(event)
|
11
|
-
Listeners.remove(self, event)
|
12
|
-
end
|
13
|
-
|
14
|
-
def emit(event, params={})
|
15
|
-
Listeners.kick(self, event, params)
|
16
|
-
end
|
17
|
-
|
18
|
-
module Listeners
|
19
|
-
extend self
|
20
|
-
|
21
|
-
def list(model, event=nil)
|
22
|
-
@listeners ||= Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = []} }
|
23
|
-
event ? @listeners[model][event.to_sym] : @listeners[model]
|
24
|
-
end
|
25
|
-
|
26
|
-
def add(model, event, *args, block)
|
27
|
-
list(model, event) << [block, *args]
|
28
|
-
model
|
29
|
-
end
|
30
|
-
|
31
|
-
def all(model, event)
|
32
|
-
list(model, event)
|
33
|
-
end
|
34
|
-
|
35
|
-
def remove(model, event)
|
36
|
-
list(model).delete event.to_sym
|
37
|
-
model
|
38
|
-
end
|
39
|
-
|
40
|
-
def kick(model, event, params)
|
41
|
-
event = Event.new(event, params) unless event.is_a?(Event)
|
42
|
-
|
43
|
-
all(model, event.name).each do |block, method_name, *args|
|
44
|
-
if !block && method_name
|
45
|
-
block = Proc.new{ |e|
|
46
|
-
a = method(method_name).arity == 0 ? [] : [e];
|
47
|
-
__send__(method_name, *a) }
|
48
|
-
context = model
|
49
|
-
elsif block && method_name # <- considering it's a context reference
|
50
|
-
context = method_name
|
51
|
-
else
|
52
|
-
context = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
args = block.arity == 0 ? [] : [event]
|
56
|
-
|
57
|
-
if context
|
58
|
-
context.instance_exec *args, &block
|
59
|
-
else
|
60
|
-
block.call *args
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
model
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Event
|
69
|
-
attr_reader :name, :params
|
70
|
-
|
71
|
-
def initialize(name, params)
|
72
|
-
@name = name.to_sym
|
73
|
-
@params = params
|
74
|
-
end
|
75
|
-
|
76
|
-
def method_missing(name, *args, &block)
|
77
|
-
if @params.has_key?(name.to_sym)
|
78
|
-
@params[name.to_sym]
|
79
|
-
else
|
80
|
-
super name, *args, &block
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
data/lib/under_os/file.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
class UnderOs::File
|
2
|
-
attr_reader :path, :mode
|
3
|
-
|
4
|
-
def self.open(path, *args, &block)
|
5
|
-
new path, *args, &block
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.read(path, *args)
|
9
|
-
new(path, *args).read
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.write(path, content)
|
13
|
-
new(path, "w"){|f| f.write(content) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.size(path)
|
17
|
-
new(path).size
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.delete(path)
|
21
|
-
NSFileManager.defaultManager.removeItemAtPath(UnderOs::File.path(path), error:nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.path(path)
|
25
|
-
path.to_s[0] == '/' ? path : NSHomeDirectory().stringByAppendingPathComponent(path)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.tmp(filename, mode="w", &block)
|
29
|
-
new NSTemporaryDirectory().stringByAppendingPathComponent(filename), mode, &block
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.exists?(path, is_dir=nil)
|
33
|
-
NSFileManager.defaultManager.fileExistsAtPath(UnderOs::File.path(path), isDirectory:is_dir)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.file?(path)
|
37
|
-
exists?(path, false)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.dir?(path)
|
41
|
-
exists?(path, true)
|
42
|
-
end
|
43
|
-
|
44
|
-
def initialize(path, mode="r", &block)
|
45
|
-
@path = UnderOs::File.path(path)
|
46
|
-
@mode = mode
|
47
|
-
|
48
|
-
yield(self) if block_given?
|
49
|
-
end
|
50
|
-
|
51
|
-
def url
|
52
|
-
@url ||= NSURL.fileURLWithPath(@path)
|
53
|
-
end
|
54
|
-
|
55
|
-
def read(size=nil)
|
56
|
-
open
|
57
|
-
data = if size == nil
|
58
|
-
@handle.readDataToEndOfFile
|
59
|
-
else
|
60
|
-
@handle.readDataOfLength(size)
|
61
|
-
end
|
62
|
-
close
|
63
|
-
|
64
|
-
@mode == "b" ? data : NSString.alloc.initWithData(data, encoding:NSUTF8StringEncoding)
|
65
|
-
end
|
66
|
-
|
67
|
-
def write(content)
|
68
|
-
if ! UnderOs::File.exists?(@path)
|
69
|
-
NSFileManager.defaultManager.createFileAtPath @path, contents:nil, attributes:nil
|
70
|
-
end
|
71
|
-
|
72
|
-
content = content.to_data('utf-8') if content.is_a?(String)
|
73
|
-
|
74
|
-
open
|
75
|
-
@handle.writeData content
|
76
|
-
close
|
77
|
-
end
|
78
|
-
|
79
|
-
def open
|
80
|
-
@handle = if @mode == "r"
|
81
|
-
NSFileHandle.fileHandleForReadingAtPath(@path)
|
82
|
-
else
|
83
|
-
NSFileHandle.fileHandleForWritingAtPath(@path)
|
84
|
-
end
|
85
|
-
|
86
|
-
@handle.seekToEndOfFile if ["w+", "a"].include?(@mode)
|
87
|
-
end
|
88
|
-
|
89
|
-
def close
|
90
|
-
@handle.closeFile
|
91
|
-
@handle = nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def seek(offset)
|
95
|
-
@handle.seekToFileOffset(offset)
|
96
|
-
end
|
97
|
-
|
98
|
-
def rewind
|
99
|
-
seek 0
|
100
|
-
end
|
101
|
-
|
102
|
-
def size
|
103
|
-
NSFileManager.defaultManager.attributesOfItemAtPath(@path, error: nil).fileSize
|
104
|
-
end
|
105
|
-
|
106
|
-
def truncate(size)
|
107
|
-
@handle.truncateFileAtOffset(size)
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
data/lib/under_os/history.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
class UnderOs::History
|
2
|
-
attr_reader :_, :navbar
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@_ = UINavigationController.alloc
|
6
|
-
@navbar = UnderOs::UI::Navbar.new(@_)
|
7
|
-
end
|
8
|
-
|
9
|
-
def root_page
|
10
|
-
@_.topViewController.wrapper
|
11
|
-
end
|
12
|
-
|
13
|
-
def root_page=(page)
|
14
|
-
@_.initWithRootViewController(page._)
|
15
|
-
end
|
16
|
-
|
17
|
-
def current_page
|
18
|
-
controller = @_.topViewController
|
19
|
-
|
20
|
-
controller.is_a?(UnderOs::Page::UIViewControllerWrap) ?
|
21
|
-
controller.wrapper : root_page
|
22
|
-
end
|
23
|
-
|
24
|
-
def push(page, animated=true)
|
25
|
-
if pages.include?(page)
|
26
|
-
pop_to(page)
|
27
|
-
else
|
28
|
-
@_.pushViewController(page._, animated: animated)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
alias :<< :push
|
33
|
-
|
34
|
-
def pop(page=nil, animated=true)
|
35
|
-
if page
|
36
|
-
@_.popToViewController(page._, animated: animated)
|
37
|
-
else
|
38
|
-
@_.popViewControllerAnimated(animated)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def pages
|
43
|
-
@_.viewControllers.map{|c| c.wrapper rescue nil }.compact
|
44
|
-
end
|
45
|
-
|
46
|
-
def pop_to(page, animated=true)
|
47
|
-
pop(page, animated)
|
48
|
-
end
|
49
|
-
|
50
|
-
def pop_to_root(animated=true)
|
51
|
-
@_.popToRootViewControllerAnimated(animated)
|
52
|
-
end
|
53
|
-
end
|
data/lib/under_os/http.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class UnderOs::HTTP
|
2
|
-
def self.get(url, options={}, &block)
|
3
|
-
request url, options.merge(method: :get), &block
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.post(url, options={}, &block)
|
7
|
-
request url, options.merge(method: :post), &block
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.put(url, options={}, &block)
|
11
|
-
request url, options.merge(method: :put), &block
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.patch(url, options={}, &block)
|
15
|
-
request url, options.merge(method: :patch), &block
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.head(url, options={}, &block)
|
19
|
-
request url, options.merge(method: :head), &block
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.delete(url, options={}, &block)
|
23
|
-
request url, options.merge(method: :delete), &block
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def self.request(*args, &block)
|
29
|
-
Request.new(*args, &block).send
|
30
|
-
end
|
31
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# A simple cookie jar thing
|
3
|
-
#
|
4
|
-
class UnderOs::HTTP::Cookies
|
5
|
-
def initialize(cookies, url)
|
6
|
-
@url = url.is_a?(String) ? NSURL.URLWithString(url) : url
|
7
|
-
@hash = cookies
|
8
|
-
end
|
9
|
-
|
10
|
-
def headers
|
11
|
-
NSHTTPCookie.requestHeaderFieldsWithCookies(ios_cookies)
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
headers["Cookie"]
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def ios_cookies
|
21
|
-
@hash.map do |key, value|
|
22
|
-
NSHTTPCookie.cookieWithProperties({
|
23
|
-
NSHTTPCookieDomain => @url.host,
|
24
|
-
NSHTTPCookiePath => "/",
|
25
|
-
NSHTTPCookieName => key.to_s,
|
26
|
-
NSHTTPCookieValue => value.to_s
|
27
|
-
})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# A little wrap to handle iOS HTTP requests receiving
|
3
|
-
#
|
4
|
-
class UnderOs::HTTP::Request
|
5
|
-
class Receiver
|
6
|
-
def initialize(request, stream=false)
|
7
|
-
@request = request
|
8
|
-
@stream = stream
|
9
|
-
@data = NSMutableData.dataWithCapacity(0)
|
10
|
-
end
|
11
|
-
|
12
|
-
def connection(connection, didReceiveResponse:response)
|
13
|
-
@data.setLength(0)
|
14
|
-
@response = UnderOs::HTTP::Response.new(response, @data)
|
15
|
-
|
16
|
-
emit(:response)
|
17
|
-
end
|
18
|
-
|
19
|
-
def connection(connection, didReceiveData:data)
|
20
|
-
@data.setLength(0) if @stream
|
21
|
-
@data.appendData(data)
|
22
|
-
emit(:data)
|
23
|
-
end
|
24
|
-
|
25
|
-
# def connection(connection, willCacheResponse:cachedResponse)
|
26
|
-
# return nil # don't cache
|
27
|
-
# end
|
28
|
-
|
29
|
-
def connection(connection, didFailWithError:error)
|
30
|
-
@response = UnderOs::HTTP::Response.new(error, @data)
|
31
|
-
|
32
|
-
emit(:failure)
|
33
|
-
end
|
34
|
-
|
35
|
-
def connectionDidFinishLoading(connection)
|
36
|
-
emit(:success)
|
37
|
-
end
|
38
|
-
|
39
|
-
def emit(event)
|
40
|
-
@request.emit(event, response: @response)
|
41
|
-
@request.emit(:complete, response: @response) if event == :failure || event == :success
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Options:
|
3
|
-
#
|
4
|
-
# * :method - GET, POST, ...
|
5
|
-
# * :cookies - Hash of cookie values
|
6
|
-
# * :stream - boolean, in case you want to stream stuff
|
7
|
-
# * :params - the POST/PUT/PATCH params hash
|
8
|
-
# * :encoding - the POST data encoding
|
9
|
-
#
|
10
|
-
# Events:
|
11
|
-
#
|
12
|
-
# * :response - when response header is received
|
13
|
-
# * :data - when a chunk of data is received
|
14
|
-
# * :success - when the request is successfully finished
|
15
|
-
# * :failure - when request has failed for whatever reason
|
16
|
-
# * :complete - when it's complete (either way)
|
17
|
-
#
|
18
|
-
class UnderOs::HTTP::Request
|
19
|
-
include UnderOs::Events
|
20
|
-
|
21
|
-
attr_reader :url, :method, :params
|
22
|
-
|
23
|
-
def initialize(url, options={}, &block)
|
24
|
-
@url = url
|
25
|
-
@options = options
|
26
|
-
|
27
|
-
on :complete, &block if block_given?
|
28
|
-
end
|
29
|
-
|
30
|
-
def on(*args, &block)
|
31
|
-
super *args do |event|
|
32
|
-
args = block.arity == 0 ? [] : [event.params[:response]]
|
33
|
-
block.call *args
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def send
|
38
|
-
@request = build_request
|
39
|
-
@receiver = Receiver.new(self, @options[:stream])
|
40
|
-
@connection = NSURLConnection.alloc.initWithRequest(@request, delegate:@receiver)
|
41
|
-
@connection.start
|
42
|
-
|
43
|
-
return self
|
44
|
-
end
|
45
|
-
|
46
|
-
def cancel
|
47
|
-
@connection.cancel
|
48
|
-
|
49
|
-
return self
|
50
|
-
end
|
51
|
-
|
52
|
-
def method
|
53
|
-
method = @options[:method] || :get
|
54
|
-
method = method.to_s.upcase
|
55
|
-
method = 'GET' unless %w[GET POST PUT DELETE PATCH HEAD].include?(method)
|
56
|
-
method
|
57
|
-
end
|
58
|
-
|
59
|
-
def headers
|
60
|
-
@options[:headers] || {}
|
61
|
-
end
|
62
|
-
|
63
|
-
def cookies
|
64
|
-
@options[:cookies] || {}
|
65
|
-
end
|
66
|
-
|
67
|
-
def params
|
68
|
-
@options[:params] || {}
|
69
|
-
end
|
70
|
-
|
71
|
-
def encoding
|
72
|
-
@options[:encoding] || 'utf-8'
|
73
|
-
end
|
74
|
-
|
75
|
-
protected
|
76
|
-
|
77
|
-
def build_request
|
78
|
-
query = params.to_query
|
79
|
-
url = build_url(query)
|
80
|
-
|
81
|
-
NSMutableURLRequest.requestWithURL(url).tap do |request|
|
82
|
-
request.setHTTPMethod method
|
83
|
-
|
84
|
-
headers.merge(UnderOs::HTTP::Cookies.new(cookies, url).headers).each do |key, value|
|
85
|
-
request.addValue value, forHTTPHeaderField:key
|
86
|
-
end
|
87
|
-
|
88
|
-
if %w[POST PUT PATCH DELETE].include?(method) && !query.empty?
|
89
|
-
request.addValue "application/x-www-form-urlencoded;charset=#{encoding}", forHTTPHeaderField:"Content-Type"
|
90
|
-
request.setHTTPBody query.to_data(encoding)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def build_url(query)
|
96
|
-
url = @url
|
97
|
-
|
98
|
-
if method == "GET" && !query.empty?
|
99
|
-
url += url.include?('?') ? '&' : '?'
|
100
|
-
url += query
|
101
|
-
end
|
102
|
-
|
103
|
-
NSURL.URLWithString(url)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|