fanforce-internal-utils 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +2 -0
- data/README.md +4 -0
- data/Rakefile +16 -0
- data/fanforce-internal-utils.gemspec +20 -0
- data/lib/fanforce.rb +13 -0
- data/lib/fanforce/utils.rb +6 -0
- data/lib/fanforce/utils/utils.rb +104 -0
- data/lib/fanforce/version.rb +3 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDJmZDIwNTUyZTQwYTc3N2VjMzRjMWNhZmVlODNmNmM2ODAzODFkNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGMwMTFhZmI0MmMxNjkxNmNjMTM1NDI2MDEzZDExOTA1NTMzOTIzZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjZlZGQ3ZGY3ODliN2JjMzA0NzZjM2U1N2ExODNiNjRiZWU0MTViZmZlY2M5
|
10
|
+
NDAzZGIzYjhiYTEyODM4YTI0YzdkZDlhOGMxZjA2MjUxOTY0MTljMzM5Y2Y2
|
11
|
+
NGMxMzRkZThhMmExMDVkM2MxMjkwZTkxYWRlNzNmM2FiZjNkZmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGZjMzg4MzBiZjlkODAwNzdkZDIxMzIzNzEyN2M2ZjkwZmM3MmRlZjk2YWZm
|
14
|
+
MGFlN2U3MzY1NDBhM2ZmMjE1ZmUzZWQ4NTMxM2ZkOWM0NjhlYmE3ZTJhMDM3
|
15
|
+
ZTExZjhiMWI0MTNjNDJiYmI2ODVjNjFkYzdlMTgyODkyZjkxMDA=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
.DS_Store
|
20
|
+
.idea/
|
21
|
+
.idea/*
|
22
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# Default Rake task is compile
|
7
|
+
#task :default => :compile
|
8
|
+
|
9
|
+
########################################################################
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs.push "lib"
|
13
|
+
t.libs.push "test"
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = false
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fanforce/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'fanforce-internal-utils'
|
8
|
+
gem.version = Fanforce::VERSION
|
9
|
+
gem.date = '2012-10-19'
|
10
|
+
gem.summary = %q{Internal utils library used by the Fanforce codebase.}
|
11
|
+
gem.authors = ['Caleb Clark']
|
12
|
+
gem.email = ['cclark@fanforce.com']
|
13
|
+
gem.homepage = 'http://github.com/mlabs/fanforce-internal-utils'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'multi_json', '>= 1.3.6'
|
20
|
+
end
|
data/lib/fanforce.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Fanforce::Utils
|
5
|
+
extend Fanforce::Utils
|
6
|
+
def self.included(base) base.extend(self) end
|
7
|
+
|
8
|
+
def is_blank?(obj)
|
9
|
+
obj.respond_to?(:empty?) ? obj.empty? : !obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_present?(obj)
|
13
|
+
!is_blank?(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
def symbolize_keys(object) #:nodoc:
|
17
|
+
Fanforce::InternalUtils.modify_keys(object) do |key|
|
18
|
+
key.is_a?(String) ? key.to_sym : key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_url(raw_url)
|
23
|
+
return if is_blank?(raw_url)
|
24
|
+
url = URI::parse(raw_url)
|
25
|
+
query_params = Rack::Utils.parse_query(url.query).inject({}) do |result, (k,v)|
|
26
|
+
if k !~ /^ff_.+/
|
27
|
+
result[k] = v
|
28
|
+
end
|
29
|
+
result
|
30
|
+
end
|
31
|
+
query_string = to_query_string(Hash[query_params.sort]) if is_present?(query_params)
|
32
|
+
_external_id = url.host + url.path
|
33
|
+
clean_url = "#{url.scheme}://#{url.host}#{(if ![80,443].include?(url.port) then ":#{url.port}" end)}#{url.path}#{(if is_present?(query_string) then "?#{query_string}" end)}"
|
34
|
+
|
35
|
+
{ _external_id: _external_id, clean_url: clean_url, raw_url: raw_url, query_params: query_params, query_string: query_string, scheme: url.scheme, host: url.host, port: url.port, path: url.path, fragment: url.fragment }
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_query_string(obj, namespace=nil)
|
39
|
+
return '' if is_blank?(obj)
|
40
|
+
if obj.is_a?(Array)
|
41
|
+
obj.collect { |value| to_query_string(value, "#{namespace}[]") }.join '&'
|
42
|
+
elsif obj.is_a?(Hash)
|
43
|
+
obj.collect { |key, value| to_query_string(value, namespace ? "#{namespace}[#{key}]" : key) }.sort * '&'
|
44
|
+
elsif obj.is_a?(Object)
|
45
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
46
|
+
"#{CGI.escape(Fanforce::InternalUtils.to_param(namespace))}=#{CGI.escape(Fanforce::InternalUtils.to_param(obj).to_s)}"
|
47
|
+
else
|
48
|
+
raise "Argument must be an object, hash, or array; instead it was a #{obj.class}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def curl_command(method, url, req_params)
|
53
|
+
case method.to_s.downcase.to_sym
|
54
|
+
when :get
|
55
|
+
"curl \"#{url}?#{to_query_string(req_params)}\""
|
56
|
+
when :post
|
57
|
+
"curl -X POST -d \"#{to_query_string(req_params)}\" #{url}"
|
58
|
+
when :put
|
59
|
+
"curl -X PUT -d \"#{to_query_string(req_params)}\" #{url.to_json}"
|
60
|
+
when :delete
|
61
|
+
"curl --request DELETE \"#{url}?#{to_query_string(req_params)}\""
|
62
|
+
else
|
63
|
+
raise 'Unknown request method'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
module Fanforce::InternalUtils
|
70
|
+
|
71
|
+
def self.modify_keys(object, &modifier) #:nodoc:
|
72
|
+
case object
|
73
|
+
when Array
|
74
|
+
object.map do |value|
|
75
|
+
modify_keys(value, &modifier)
|
76
|
+
end
|
77
|
+
when Hash
|
78
|
+
object.inject({}) do |result, (key, value)|
|
79
|
+
new_key = modifier.call(key)
|
80
|
+
new_value = modify_keys(value, &modifier)
|
81
|
+
result.merge! new_key => new_value
|
82
|
+
end
|
83
|
+
else
|
84
|
+
object
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.to_param(obj, namespace=nil)
|
89
|
+
if obj.is_a?(Array)
|
90
|
+
collect { |e| to_param(e) }.join '/'
|
91
|
+
elsif obj.is_a?(Hash)
|
92
|
+
to_query_string(obj, namespace)
|
93
|
+
elsif obj.is_a?(NilClass)
|
94
|
+
obj
|
95
|
+
elsif obj.is_a?(TrueClass)
|
96
|
+
obj
|
97
|
+
elsif obj.is_a?(FalseClass)
|
98
|
+
obj
|
99
|
+
elsif obj.is_a?(Object)
|
100
|
+
obj.to_s
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fanforce-internal-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Clark
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.6
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- cclark@fanforce.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- fanforce-internal-utils.gemspec
|
39
|
+
- lib/fanforce.rb
|
40
|
+
- lib/fanforce/utils.rb
|
41
|
+
- lib/fanforce/utils/utils.rb
|
42
|
+
- lib/fanforce/version.rb
|
43
|
+
homepage: http://github.com/mlabs/fanforce-internal-utils
|
44
|
+
licenses: []
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Internal utils library used by the Fanforce codebase.
|
66
|
+
test_files: []
|