fanforce 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTI1NmU2MDI2NjM0ODlhZGViYzRmNGMzYzBlZmYxYmYyNWI3ZTMzNA==
4
+ MTI2ZWIwNWRjZmQxZTcyZDkzN2EzZjFhYzQ4NjhkNDI0YjI2ZjFiMA==
5
5
  data.tar.gz: !binary |-
6
- NTEwNWMzOWE3NThiMjc3OTRlMjY1ODNhYzYwMjNjN2FkNTc5NTY5Ng==
6
+ OTYxMzkwZmNhNTdhZTI5NjVlMWU5MjAyZjc3MzNmMzQxN2Q2YzJlOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTEzZjI0ODBlYTczODU3ZDBlMTM3MmU0NjkzM2UzMDJjNzY5NDIxZmY2MDQ1
10
- YmRhZDgwZDQyMTcwNGVjNzQ2MjY2NjEzNTI3NWVjNDhlODAyY2JkZjVkOGU4
11
- ZTY1YTIwY2Q5NWYxM2VjMzBlYjIzZTlkYzk3M2JhZmQ5MGY5OTc=
9
+ ODNkOWNiMzRmYTI0NzI3Y2RiOGQ4YTYxMmEyNGJmODQ0Mjg5MTE3ODgwYjE4
10
+ ZTQzMzg3YTdiOGJkNGRkNzgzODE5YzViMDJmZWNjZGU0ODE3NWI4ZDk3MDg1
11
+ ZmQ1NTY1N2Q2ZjJmZjlhMTIxM2RhYWE5MWZhYWQyNmJhYThkZDc=
12
12
  data.tar.gz: !binary |-
13
- YmE1ZTFiZDkwZTc5YWM5YWFmZWRkNjNhY2Y5Njk4MTE1MjRiNTRlNDkxZjc2
14
- NTJmMmU3MTE0MjYxYjZmYjg0NTI3M2UwYzMxNTg1ODgyNjkwM2ZlMjA3NTQ3
15
- NGY4NjIyMDY5N2U5ODlhNjM4ZDVjNTMxNzQ4YTkxZjFjMjkzMDM=
13
+ NjUwNDkyNGRjMmFhOTFiNzA5OWIwMTZlZGNjZjhmNWFmZmU1NGQ1MDk0MjQ4
14
+ OTVlM2UxODdkNDBmNDY3YWRhOTg0MmI5ODU5NjE3ZjIxZjk4MGM3YTY4YmQy
15
+ YmVmNjg1NzUwNTlkZWJjNDRmZDRkNjJiOTJkYTJmOTBmOWFkMmY=
data/fanforce.gemspec CHANGED
@@ -16,4 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
+
20
+ gem.add_runtime_dependency 'rack'
21
+ gem.add_runtime_dependency 'oj', '~> 2.1.4'
22
+ gem.add_runtime_dependency 'multi_json', '>= 1.7.2'
19
23
  end
@@ -1,5 +1,8 @@
1
+ require_relative 'domains'
2
+ require_relative 'utils'
3
+
1
4
  class Fanforce
2
- require_relative 'domains'
5
+ include Fanforce::Utils
3
6
 
4
7
  def self.base_domain
5
8
  Fanforce::Domains.method(ENV['RACK_ENV'] || 'development').call[:base]
@@ -0,0 +1,129 @@
1
+ require 'uri'
2
+ require 'rack/utils'
3
+ require 'multi_json'
4
+
5
+ module Fanforce::Utils
6
+ extend Fanforce::Utils
7
+ def self.included(base) base.extend(self) end
8
+
9
+ def is_blank?(obj)
10
+ obj.respond_to?(:empty?) ? obj.empty? : !obj
11
+ end
12
+
13
+ def is_present?(obj)
14
+ !is_blank?(obj)
15
+ end
16
+
17
+ def symbolize_keys(object) #:nodoc:
18
+ Fanforce::InternalUtils.modify_keys(object) do |key|
19
+ key.is_a?(String) ? key.to_sym : key
20
+ end
21
+ end
22
+
23
+ def parse_url(raw_url)
24
+ return if is_blank?(raw_url)
25
+ url = URI::parse(raw_url)
26
+ query_params = Rack::Utils.parse_nested_query(url.query).inject({}) do |result, (k,v)|
27
+ if k !~ /^ff_.+/
28
+ result[k] = v
29
+ end
30
+ result
31
+ end
32
+ query_string = to_query_string(Hash[query_params.sort]) if is_present?(query_params)
33
+ _external_id = url.host + url.path
34
+ 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)}"
35
+
36
+ { _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 }
37
+ end
38
+
39
+ def to_query_string(obj, namespace=nil)
40
+ return '' if is_blank?(obj)
41
+ if obj.is_a?(Array)
42
+ obj.collect { |value| to_query_string(value, "#{namespace}[]") }.join '&'
43
+ elsif obj.is_a?(Hash)
44
+ obj.collect { |key, value| to_query_string(value, namespace ? "#{namespace}[#{key}]" : key) }.sort * '&'
45
+ elsif obj.is_a?(Object)
46
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
47
+ "#{CGI.escape(Fanforce::InternalUtils.to_param(namespace))}=#{CGI.escape(Fanforce::InternalUtils.to_param(obj).to_s)}"
48
+ else
49
+ raise "Argument must be an object, hash, or array; instead it was a #{obj.class}"
50
+ end
51
+ end
52
+
53
+ def curl_command(method, url, req_params)
54
+ case method.to_s.downcase.to_sym
55
+ when :get
56
+ "curl \"#{url}?#{to_query_string(req_params)}\""
57
+ when :post
58
+ "curl -X POST -d \"#{to_query_string(req_params)}\" #{url}"
59
+ when :put
60
+ "curl -X PUT -d \"#{to_query_string(req_params)}\" #{url.to_json}"
61
+ when :delete
62
+ "curl --request DELETE \"#{url}?#{to_query_string(req_params)}\""
63
+ when :options
64
+ "curl -X OPTIONS \"#{url}?#{to_query_string(req_params)}\""
65
+ else
66
+ raise 'Unknown request method'
67
+ end
68
+ end
69
+
70
+ def decode_json(str, symbolize_keys=true)
71
+ MultiJson.load(str, :symbolize_keys => symbolize_keys)
72
+ end
73
+
74
+ # Creates a string representation of a javascript object for $.tmpl
75
+ def compile_jquery_tmpls(options={}, &block)
76
+ begin require 'haml' rescue LoadError raise 'You must have the haml gem installed to use Fanforce.compile_jquery_templates.' end
77
+ context = Object.new
78
+ class << context
79
+ include Haml::Helpers
80
+ end
81
+ context.init_haml_helpers
82
+
83
+ format = options[:format] == 'html' ? :html : :json
84
+
85
+ return context.capture_haml(&block) if format == :html
86
+ single_line_html = context.capture_haml(&block).split(/\r?\n/).inject('') {|sl, l| sl += l.strip + ' ' }
87
+ matches = single_line_html.scan(/<script id=[\"'](.*?)[\"'](?:.*?)>(.*?)(?:<\/script>)/mi)
88
+
89
+ matches.inject({}) {|t,m| t[m[0]] = m[1]; t }.to_json
90
+ end
91
+
92
+ end
93
+
94
+ module Fanforce::InternalUtils
95
+
96
+ def self.modify_keys(object, &modifier) #:nodoc:
97
+ case object
98
+ when Array
99
+ object.map do |value|
100
+ modify_keys(value, &modifier)
101
+ end
102
+ when Hash
103
+ object.inject({}) do |result, (key, value)|
104
+ new_key = modifier.call(key)
105
+ new_value = modify_keys(value, &modifier)
106
+ result.merge! new_key => new_value
107
+ end
108
+ else
109
+ object
110
+ end
111
+ end
112
+
113
+ def self.to_param(obj, namespace=nil)
114
+ if obj.is_a?(Array)
115
+ collect { |e| to_param(e) }.join '/'
116
+ elsif obj.is_a?(Hash)
117
+ to_query_string(obj, namespace)
118
+ elsif obj.is_a?(NilClass)
119
+ obj
120
+ elsif obj.is_a?(TrueClass)
121
+ obj
122
+ elsif obj.is_a?(FalseClass)
123
+ obj
124
+ elsif obj.is_a?(Object)
125
+ obj.to_s
126
+ end
127
+ end
128
+
129
+ end
@@ -1,3 +1,3 @@
1
1
  class Fanforce
2
- VERSION = '0.14.0'
2
+ VERSION = '0.15.0'
3
3
  end
data/lib/fanforce.rb CHANGED
@@ -1,2 +1,14 @@
1
- require_relative 'fanforce/_base'
2
- require_relative 'fanforce/version'
1
+ class Fanforce
2
+ def self.env(&block)
3
+ if !block.nil?
4
+ @env = block
5
+ elsif !@env.nil?
6
+ @env.call
7
+ else
8
+ {}
9
+ end
10
+ end
11
+ require_relative 'fanforce/_base'
12
+ require_relative 'fanforce/version'
13
+ end
14
+
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-06 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.7.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.7.2
13
55
  description: Core gem used internally by other Fanforce gems
14
56
  email:
15
57
  - cclark@fanforce.com
@@ -26,6 +68,7 @@ files:
26
68
  - lib/fanforce.rb
27
69
  - lib/fanforce/_base.rb
28
70
  - lib/fanforce/domains.rb
71
+ - lib/fanforce/utils.rb
29
72
  - lib/fanforce/version.rb
30
73
  homepage: http://github.com/fanforce/fanforce
31
74
  licenses: []