fanforce 0.7.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE.md +1 -1
- data/README.md +3 -132
- data/Rakefile +2 -2
- data/fanforce.gemspec +6 -11
- data/lib/fanforce/domains.rb +45 -0
- data/lib/fanforce/version.rb +3 -0
- metadata +9 -60
- data/.rbenv-gemsets +0 -1
- data/.rbenv-version +0 -1
- data/lib/fanforce.rb +0 -9
- data/lib/fanforce/api/_main.rb +0 -100
- data/lib/fanforce/api/error.rb +0 -67
- data/lib/fanforce/api/ff_globals.rb +0 -73
- data/lib/fanforce/api/response.rb +0 -111
- data/lib/fanforce/api/utils.rb +0 -67
- data/lib/fanforce/api/version.rb +0 -5
- data/test/fanforce_test.rb +0 -22
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YThhNWRiNmFkOTY5OGNlMmQyODNiNjlkMDA1Y2Q1MDA5YzE2Y2FmYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDBjMGI3M2U1MDViZTkzZDI4NThmMTAxYmJlZmEyYWFiYjFmZTdlNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWI2ODJhMmViY2I4OWUzNmZjZDI5NDQ4NWQxNmQ4NDQ4ZTdmNjYzYWFkNGVk
|
10
|
+
ZDdkYjM4ODIxZWZlOGVlOTgyNDQxZWVlN2E5ZDliODJmM2QyZGI2ZTkxMjIw
|
11
|
+
MjMyYjZlNTZjYTg4YzNmZDk2YmZiY2U0NTM3NTE5MWJjMDQ0OTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDA0YmM4N2U4ZTg1YTEyNjk2MGM4M2VjMWQwNWQ2MmQ5NGMyMmJiYjhhM2I3
|
14
|
+
MjEwOGZiOGE4NjE1Y2I0NmFiZjNjNTg0NWUxZmE3MzAyNjM0NWM0NGQ1N2I5
|
15
|
+
Y2U5NzZkNmUzODYwODkyODc1Yzk1MTQ2OWEzZDE2NWY2Y2RmMjE=
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,133 +1,4 @@
|
|
1
|
-
|
1
|
+
fanforce
|
2
|
+
========
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
```
|
6
|
-
$ gem install fanforce
|
7
|
-
```
|
8
|
-
|
9
|
-
To build and install the development branch yourself from the latest source:
|
10
|
-
|
11
|
-
```
|
12
|
-
$ git clone git@github.com:mlabs/fanforce-ruby.git
|
13
|
-
$ cd fanforce-ruby
|
14
|
-
$ git checkout master
|
15
|
-
$ rake gem
|
16
|
-
$ gem install pkg/fanforce-{version}
|
17
|
-
```
|
18
|
-
|
19
|
-
## Getting Started
|
20
|
-
|
21
|
-
### Set It Up
|
22
|
-
|
23
|
-
``` ruby
|
24
|
-
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
|
25
|
-
require 'fanforce'
|
26
|
-
|
27
|
-
# put your own credentials here
|
28
|
-
api_key = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
|
29
|
-
|
30
|
-
# set up a client to talk to the Fanforce API
|
31
|
-
ff = Fanforce.new api_key
|
32
|
-
```
|
33
|
-
|
34
|
-
### Making Your First Call
|
35
|
-
|
36
|
-
``` ruby
|
37
|
-
# get your api access info
|
38
|
-
ff.get('/access_info', {})
|
39
|
-
```
|
40
|
-
|
41
|
-
## Full REST Access
|
42
|
-
|
43
|
-
### GET
|
44
|
-
|
45
|
-
``` ruby
|
46
|
-
ff.get('/', {})
|
47
|
-
```
|
48
|
-
|
49
|
-
### POST
|
50
|
-
|
51
|
-
``` ruby
|
52
|
-
ff.post('/', {})
|
53
|
-
```
|
54
|
-
|
55
|
-
### PUT
|
56
|
-
|
57
|
-
``` ruby
|
58
|
-
ff.put('/', {})
|
59
|
-
```
|
60
|
-
|
61
|
-
### DELETE
|
62
|
-
|
63
|
-
``` ruby
|
64
|
-
ff.delete('/')
|
65
|
-
```
|
66
|
-
|
67
|
-
## Error Handling
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
begin
|
71
|
-
ff.get('/bad_page')
|
72
|
-
rescue Fanforce::Error => e
|
73
|
-
puts e.curl_command
|
74
|
-
end
|
75
|
-
```
|
76
|
-
|
77
|
-
e.curl_command
|
78
|
-
e.response_code
|
79
|
-
e.response_body
|
80
|
-
e.request_url
|
81
|
-
e.request_params
|
82
|
-
|
83
|
-
BadRequestError
|
84
|
-
|
85
|
-
## Utils
|
86
|
-
|
87
|
-
ff.get_url(path, query_params)
|
88
|
-
|
89
|
-
ff.curl_command(method, path, query_params)
|
90
|
-
|
91
|
-
ff.validate_auth
|
92
|
-
|
93
|
-
ff.to_query_string
|
94
|
-
|
95
|
-
ff.compile_jquery_tmpls
|
96
|
-
|
97
|
-
ff.decode_json
|
98
|
-
|
99
|
-
ff.parse_url
|
100
|
-
|
101
|
-
ff.remove_sensitive_params
|
102
|
-
|
103
|
-
ff.remove_internal_params
|
104
|
-
|
105
|
-
## Handling Results
|
106
|
-
|
107
|
-
response.result
|
108
|
-
response.results
|
109
|
-
|
110
|
-
response.total_results
|
111
|
-
response.current_results
|
112
|
-
response.current_page
|
113
|
-
response.total_pages
|
114
|
-
|
115
|
-
## Paging
|
116
|
-
|
117
|
-
response.prev_url
|
118
|
-
response.next_url
|
119
|
-
|
120
|
-
## Logging
|
121
|
-
|
122
|
-
By default logging is turned off.
|
123
|
-
```ruby
|
124
|
-
Fanforce.config do |config|
|
125
|
-
config.logging = true
|
126
|
-
end
|
127
|
-
```
|
128
|
-
|
129
|
-
For more info, see RestClient.logging.
|
130
|
-
|
131
|
-
## More Information
|
132
|
-
|
133
|
-
Visit the Fanforce Developers site to explore the full API access methods available.
|
4
|
+
foundational gem used internally by other fanforce gems
|
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ task :default => :build
|
|
9
9
|
########################################################################
|
10
10
|
|
11
11
|
Rake::TestTask.new do |t|
|
12
|
-
t.libs.push
|
13
|
-
t.libs.push
|
12
|
+
t.libs.push 'lib'
|
13
|
+
t.libs.push 'test'
|
14
14
|
t.pattern = 'test/**/*_test.rb'
|
15
15
|
t.verbose = false
|
16
16
|
end
|
data/fanforce.gemspec
CHANGED
@@ -1,24 +1,19 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'fanforce/
|
4
|
+
require 'fanforce/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'fanforce'
|
8
|
-
gem.version = Fanforce::
|
9
|
-
gem.date = '
|
10
|
-
gem.summary = %q{
|
11
|
-
gem.description = %q{
|
8
|
+
gem.version = Fanforce::VERSION
|
9
|
+
gem.date = '2013-08-27'
|
10
|
+
gem.summary = %q{Core Fanforce gem}
|
11
|
+
gem.description = %q{Core gem used internally by other Fanforce gems}
|
12
12
|
gem.authors = ['Caleb Clark']
|
13
13
|
gem.email = ['cclark@fanforce.com']
|
14
|
-
gem.homepage = 'http://github.com/
|
14
|
+
gem.homepage = 'http://github.com/fanforce/fanforce'
|
15
15
|
|
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 'multi_json', '~> 1.3'
|
21
|
-
gem.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
22
|
-
|
23
|
-
gem.add_runtime_dependency 'fanforce-internal-errors', '~> 0.1'
|
24
19
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Fanforce
|
2
|
+
|
3
|
+
if ENV['RACK_ENV'] == 'development'
|
4
|
+
TOP_LEVEL_DOMAIN = ENV['FANFORCE_GEM_TOP_LEVEL_DOMAIN'] || 'gg'
|
5
|
+
BASE_DOMAIN = ENV['FANFORCE_GEM_BASE_DOMAIN'] || 'fanforce.' + TOP_LEVEL_DOMAIN
|
6
|
+
SMARTURL_DOMAIN = 'fanforc.gg'
|
7
|
+
FF_APP_DOMAIN = 'ffapp.gg'
|
8
|
+
FF_PLUGIN_DOMAIN = 'ffplugin.gg'
|
9
|
+
FF_WIDGET_DOMAIN = 'ffwidget.gg'
|
10
|
+
|
11
|
+
elsif ENV['RACK_ENV'] == 'test'
|
12
|
+
BASE_DOMAIN = 'fanforce.gg'
|
13
|
+
SMARTURL_DOMAIN = 'fanforc.gg'
|
14
|
+
FF_APP_DOMAIN = 'ffapp.gg'
|
15
|
+
FF_PLUGIN_DOMAIN = 'ffplugin.gg'
|
16
|
+
FF_WIDGET_DOMAIN = 'ffwidget.gg'
|
17
|
+
|
18
|
+
elsif ENV['RACK_ENV'] == 'staging'
|
19
|
+
BASE_DOMAIN = 'fanforce-staging.com'
|
20
|
+
SMARTURL_DOMAIN = 'fanforc.us'
|
21
|
+
FF_APP_DOMAIN = 'ffapp.us'
|
22
|
+
FF_PLUGIN_DOMAIN = 'ffplugin.us'
|
23
|
+
FF_WIDGET_DOMAIN = 'ffwidget.us'
|
24
|
+
|
25
|
+
else
|
26
|
+
BASE_DOMAIN = 'fanforce.com'
|
27
|
+
SMARTURL_DOMAIN = 'fanforce.io'
|
28
|
+
FF_APP_DOMAIN = 'ffapp.io'
|
29
|
+
FF_PLUGIN_DOMAIN = 'ffplugin.io'
|
30
|
+
FF_WIDGET_DOMAIN = 'ffwidget.io'
|
31
|
+
end
|
32
|
+
|
33
|
+
API_DOMAIN = 'api.' + BASE_DOMAIN
|
34
|
+
I_DOMAIN = 'i.' + BASE_DOMAIN
|
35
|
+
WEBSITE_DOMAIN = BASE_DOMAIN
|
36
|
+
DEVELOPERS_DOMAIN = 'developers.' + BASE_DOMAIN
|
37
|
+
CONTROLLER_DOMAIN = 'controller.' + BASE_DOMAIN
|
38
|
+
ADDON_MANAGEMENT_URL = CONTROLLER_DOMAIN + '/db'
|
39
|
+
|
40
|
+
# these should be moved to edition
|
41
|
+
APP_DOMAIN = 'app.' + BASE_DOMAIN
|
42
|
+
SIGNUP_DOMAIN = 'signup.' + BASE_DOMAIN
|
43
|
+
MARKETPLACE_DOMAIN = 'appstore.' + BASE_DOMAIN
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,58 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.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:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: multi_json
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
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'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rest-client
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6.7
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6.7
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fanforce-internal-errors
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.1'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.1'
|
55
|
-
description: Ruby API wrapper that interfaces with all six Fanforce APIs.
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Core gem used internally by other Fanforce gems
|
56
14
|
email:
|
57
15
|
- cclark@fanforce.com
|
58
16
|
executables: []
|
@@ -60,22 +18,14 @@ extensions: []
|
|
60
18
|
extra_rdoc_files: []
|
61
19
|
files:
|
62
20
|
- .gitignore
|
63
|
-
- .rbenv-gemsets
|
64
|
-
- .rbenv-version
|
65
21
|
- Gemfile
|
66
22
|
- LICENSE.md
|
67
23
|
- README.md
|
68
24
|
- Rakefile
|
69
25
|
- fanforce.gemspec
|
70
|
-
- lib/fanforce.rb
|
71
|
-
- lib/fanforce/
|
72
|
-
|
73
|
-
- lib/fanforce/api/ff_globals.rb
|
74
|
-
- lib/fanforce/api/response.rb
|
75
|
-
- lib/fanforce/api/utils.rb
|
76
|
-
- lib/fanforce/api/version.rb
|
77
|
-
- test/fanforce_test.rb
|
78
|
-
homepage: http://github.com/mlabs/fanforce-ruby
|
26
|
+
- lib/fanforce/domains.rb
|
27
|
+
- lib/fanforce/version.rb
|
28
|
+
homepage: http://github.com/fanforce/fanforce
|
79
29
|
licenses: []
|
80
30
|
metadata: {}
|
81
31
|
post_install_message:
|
@@ -97,6 +47,5 @@ rubyforge_project:
|
|
97
47
|
rubygems_version: 2.0.3
|
98
48
|
signing_key:
|
99
49
|
specification_version: 4
|
100
|
-
summary:
|
101
|
-
test_files:
|
102
|
-
- test/fanforce_test.rb
|
50
|
+
summary: Core Fanforce gem
|
51
|
+
test_files: []
|
data/.rbenv-gemsets
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
fanforce-ruby
|
data/.rbenv-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.9.3-p194
|
data/lib/fanforce.rb
DELETED
data/lib/fanforce/api/_main.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'rest-client'
|
2
|
-
require_relative 'utils'
|
3
|
-
require_relative 'response'
|
4
|
-
|
5
|
-
module Fanforce::Api
|
6
|
-
include Fanforce::Api::Utils
|
7
|
-
include Fanforce::Errors
|
8
|
-
|
9
|
-
def self.included(base) base.extend(self) end
|
10
|
-
|
11
|
-
def initialize(arg={})
|
12
|
-
if arg.is_a?(Hash)
|
13
|
-
add_params(arg)
|
14
|
-
auth(@params) if @params.length > 0
|
15
|
-
elsif arg.is_a?(String)
|
16
|
-
auth(arg)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def params
|
21
|
-
@params ||= {}
|
22
|
-
end
|
23
|
-
|
24
|
-
def add_params(params_to_add)
|
25
|
-
params.merge!(collect_known_params params_to_add)
|
26
|
-
end
|
27
|
-
|
28
|
-
def url(path, req_params={})
|
29
|
-
req_params = apply_auth(req_params)
|
30
|
-
"#{complete_url(path)}?#{to_query_string(req_params)}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def curl_command(method, path, req_params={})
|
34
|
-
req_params = apply_auth(req_params)
|
35
|
-
Fanforce::Utils.curl_command(method, complete_url(path), req_params)
|
36
|
-
end
|
37
|
-
|
38
|
-
def get(path, req_params={})
|
39
|
-
req_params = apply_auth(req_params)
|
40
|
-
RestClient.get(url(path, req_params), :accept => :json) do |response, request, result, &block|
|
41
|
-
Fanforce::Response.process(response, request, complete_url(path), req_params)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def post(path, req_params={})
|
46
|
-
url = complete_url(path)
|
47
|
-
req_params = apply_auth(req_params)
|
48
|
-
RestClient.post(url, req_params.to_json, :content_type => :json, :accept => :json) do |response, request, result, &block|
|
49
|
-
Fanforce::Api::Response.process(response, request, url, req_params)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def put(path, req_params={})
|
54
|
-
url = complete_url(path)
|
55
|
-
req_params = apply_auth(req_params)
|
56
|
-
RestClient.put(url, req_params.to_json, :content_type => :json, :accept => :json) do |response, request, result, &block|
|
57
|
-
Fanforce::Api::Response.process(response, request, url, req_params)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def delete(path, req_params={})
|
62
|
-
url = complete_url(path)
|
63
|
-
req_params = apply_auth(req_params)
|
64
|
-
RestClient.delete(url(path, req_params), :accept => :json) do |response, request, result, &block|
|
65
|
-
Fanforce::Api::Response.process(response, request, url, req_params)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def identify(req_params)
|
70
|
-
post '/bie/identify', req_params
|
71
|
-
{success: true}
|
72
|
-
end
|
73
|
-
|
74
|
-
def track(plugin_id, req_params)
|
75
|
-
post '/bie/track', req_params.merge(plugin_id: plugin_id)
|
76
|
-
{success: true}
|
77
|
-
end
|
78
|
-
|
79
|
-
def auth(auth_data=nil)
|
80
|
-
@auth_hash ||= {}
|
81
|
-
return @auth_hash if is_blank?(auth_data)
|
82
|
-
auth_data = auth_data.is_a?(Hash) ? auth_data.symbolize_keys : {api_key: auth_data.to_s}
|
83
|
-
@auth_hash.merge! remove_nil_values(api_key: auth_data[:api_key], fanforce_id: auth_data[:fanforce_id], fanforce_slug: auth_data[:fanforce_slug])
|
84
|
-
params.merge!(@auth_hash)
|
85
|
-
valid_auth?
|
86
|
-
end
|
87
|
-
|
88
|
-
def valid_auth?
|
89
|
-
is_present?(@auth_hash) and is_present?(@auth_hash[:api_key]) and is_present?(@auth_hash[:fanforce_id])
|
90
|
-
end
|
91
|
-
|
92
|
-
def apply_auth(req_params)
|
93
|
-
req_params.merge(@auth_hash || {})
|
94
|
-
end
|
95
|
-
|
96
|
-
def complete_url(path)
|
97
|
-
'http://' + $API_DOMAIN + path
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
data/lib/fanforce/api/error.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require_relative 'utils'
|
2
|
-
|
3
|
-
class Fanforce::Api::Error < StandardError
|
4
|
-
attr_accessor :response, :request, :requested_url, :requested_params, :errors
|
5
|
-
|
6
|
-
def initialize(message, response, request, requested_url, requested_params)
|
7
|
-
@response = response
|
8
|
-
@request = request
|
9
|
-
@requested_url = requested_url
|
10
|
-
@requested_params = requested_params
|
11
|
-
@message = message
|
12
|
-
super(message)
|
13
|
-
end
|
14
|
-
|
15
|
-
def curl_command
|
16
|
-
method = begin @request.method rescue nil end
|
17
|
-
Fanforce::Utils.curl_command(method, @requested_url, @requested_params)
|
18
|
-
end
|
19
|
-
|
20
|
-
def code; @response.respond_to?(:code) ? @response.code : 500 end
|
21
|
-
def to_s; @message end
|
22
|
-
def to_hash; {} end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Fanforce::Api::ServerError < Fanforce::Api::Error
|
26
|
-
|
27
|
-
def initialize(response, request, requested_url, requested_params)
|
28
|
-
@response_body = response.to_s
|
29
|
-
|
30
|
-
begin
|
31
|
-
@response_hash = Fanforce::Utils.decode_json(response)
|
32
|
-
@errors = @response_hash[:errors]
|
33
|
-
rescue Exception => e
|
34
|
-
raise Fanforce::Api::DecodingError.new(e, response, request, requested_url, requested_params)
|
35
|
-
end
|
36
|
-
|
37
|
-
super(response.to_s, response, request, requested_url, requested_params)
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_hash
|
41
|
-
@response_hash
|
42
|
-
end
|
43
|
-
|
44
|
-
def curl_command
|
45
|
-
method = begin @request.method rescue nil end
|
46
|
-
Fanforce::Utils.curl_command(method, @requested_url, @requested_params)
|
47
|
-
end
|
48
|
-
|
49
|
-
def code; @response.code end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
class Fanforce::Api::DecodingError < Fanforce::Api::Error
|
54
|
-
|
55
|
-
def initialize(e, response, request, requested_url, requested_params)
|
56
|
-
@message = "There was a Fanforce gem error while decoding JSON response: #{e.message}"
|
57
|
-
@errors = [{message: @message}]
|
58
|
-
super(@message, response, request, requested_url, requested_params)
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_hash
|
62
|
-
{errors: @errors}
|
63
|
-
end
|
64
|
-
|
65
|
-
def code; 500 end
|
66
|
-
|
67
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
if !ENV['RACK_ENV'] or ENV['RACK_ENV'] == 'development'
|
2
|
-
top_level_domain = ENV['FANFORCE_GEM_TOP_LEVEL_DOMAIN'] || 'gg'
|
3
|
-
$BASE_DOMAIN = ENV['FANFORCE_GEM_BASE_DOMAIN'] || 'fanforce.' + top_level_domain
|
4
|
-
$APP_DOMAIN = 'app.' + $BASE_DOMAIN
|
5
|
-
$API_DOMAIN = 'api.' + $BASE_DOMAIN
|
6
|
-
$I_DOMAIN = 'i.' + $BASE_DOMAIN
|
7
|
-
$WEBSITE_DOMAIN = $BASE_DOMAIN
|
8
|
-
|
9
|
-
$SMARTURL_DOMAIN = 'fanforc.' + top_level_domain
|
10
|
-
$FF_PLUGIN_DOMAIN = 'ffplugin.' + top_level_domain
|
11
|
-
$FF_APP_DOMAIN = 'ffapp.' + top_level_domain
|
12
|
-
$FF_WIDGET_DOMAIN = 'ffwidget.' + top_level_domain
|
13
|
-
|
14
|
-
$DEVS_DOMAIN = 'technical%40mobilizationlabs.com:zE27fdevelopers@developers-fanforce.dotcloud.com' # or localhost:3000'
|
15
|
-
|
16
|
-
$PUSHER_APP_ID = '23240'
|
17
|
-
$PUSHER_KEY = '029caf227a64c8e82e99'
|
18
|
-
$PUSHER_SECRET = '3169163d2e27de9a2291'
|
19
|
-
|
20
|
-
elsif ENV['RACK_ENV'] == 'test'
|
21
|
-
$BASE_DOMAIN = 'fanforce.gg'
|
22
|
-
$APP_DOMAIN = 'app.' + $BASE_DOMAIN
|
23
|
-
$API_DOMAIN = 'api.' + $BASE_DOMAIN
|
24
|
-
$I_DOMAIN = 'i.' + $BASE_DOMAIN
|
25
|
-
$WEBSITE_DOMAIN = $BASE_DOMAIN
|
26
|
-
|
27
|
-
$SMARTURL_DOMAIN = 'fanforc.gg'
|
28
|
-
$FF_PLUGIN_DOMAIN = 'ffplugin.gg'
|
29
|
-
$FF_WIDGET_DOMAIN = 'ffwidget.gg'
|
30
|
-
$FF_APP_DOMAIN = 'ffapp.gg'
|
31
|
-
|
32
|
-
$DEVS_DOMAIN = 'technical%40mobilizationlabs.com:zE27fdevelopers@developers-fanforce.dotcloud.com'
|
33
|
-
|
34
|
-
$PUSHER_APP_ID = '23243'
|
35
|
-
$PUSHER_KEY = '7bcc87b3c55301f687b9'
|
36
|
-
$PUSHER_SECRET = '61c760c05430e68d7e8d'
|
37
|
-
|
38
|
-
elsif ENV['RACK_ENV'] == 'qa'
|
39
|
-
$BASE_DOMAIN = 'fanforce-qa.com'
|
40
|
-
$APP_DOMAIN = 'app.' + $BASE_DOMAIN
|
41
|
-
$API_DOMAIN = 'api.' + $BASE_DOMAIN
|
42
|
-
$I_DOMAIN = 'i.' + $BASE_DOMAIN
|
43
|
-
$WEBSITE_DOMAIN = $BASE_DOMAIN
|
44
|
-
|
45
|
-
$SMARTURL_DOMAIN = 'fanforc.us'
|
46
|
-
$FF_PLUGIN_DOMAIN = 'ffplugin.us'
|
47
|
-
$FF_APP_DOMAIN = 'ffapp.us'
|
48
|
-
$FF_WIDGET_DOMAIN = 'ffwidget.us'
|
49
|
-
|
50
|
-
$DEVS_DOMAIN = 'technical%40mobilizationlabs.com:zE27fdevelopers@developers-fanforce.dotcloud.com'
|
51
|
-
|
52
|
-
$PUSHER_APP_ID = '14778'
|
53
|
-
$PUSHER_KEY = 'b5e2e23fb9542798ef38'
|
54
|
-
$PUSHER_SECRET = '7bfba2003df078ca64e9'
|
55
|
-
|
56
|
-
elsif ENV['RACK_ENV'] == 'production'
|
57
|
-
$BASE_DOMAIN = 'fanforce.com'
|
58
|
-
$APP_DOMAIN = 'app.' + $BASE_DOMAIN
|
59
|
-
$API_DOMAIN = 'api.' + $BASE_DOMAIN
|
60
|
-
$I_DOMAIN = 'i.' + $BASE_DOMAIN
|
61
|
-
$WEBSITE_DOMAIN = $BASE_DOMAIN
|
62
|
-
|
63
|
-
$SMARTURL_DOMAIN = 'fanforce.io'
|
64
|
-
$FF_PLUGIN_DOMAIN = 'ffplugin.io'
|
65
|
-
$FF_APP_DOMAIN = 'ffapp.io'
|
66
|
-
$FF_WIDGET_DOMAIN = 'ffwidget.io'
|
67
|
-
|
68
|
-
$DEVS_DOMAIN = 'technical%40mobilizationlabs.com:zE27fdevelopers@developers-fanforce.dotcloud.com'
|
69
|
-
|
70
|
-
$PUSHER_APP_ID = '14778'
|
71
|
-
$PUSHER_KEY = 'b5e2e23fb9542798ef38'
|
72
|
-
$PUSHER_SECRET = '7bfba2003df078ca64e9'
|
73
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
class Fanforce::Api::Response
|
2
|
-
attr_reader :curl_command, :requested_url, :requested_params
|
3
|
-
|
4
|
-
def self.process(response, request, requested_url, requested_params)
|
5
|
-
raise Fanforce::Api::ServerError.new(response, request, requested_url, requested_params) if response.code > 201
|
6
|
-
begin response_hash = Fanforce::Utils.decode_json(response)
|
7
|
-
rescue Exception => e; raise Fanforce::Api::DecodingError.new(e, response, request, requested_url, requested_params) end
|
8
|
-
if response_hash[:results]
|
9
|
-
Fanforce::Api::Results.new(response_hash, response, request, requested_url, requested_params)
|
10
|
-
else
|
11
|
-
Fanforce::Api::Result.new(response_hash, response, request, requested_url, requested_params)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
class Fanforce::Api::Result < Hash
|
18
|
-
attr_reader :requested_url, :requested_params
|
19
|
-
|
20
|
-
def initialize(response_hash, response, request, requested_url, requested_params)
|
21
|
-
@response = response
|
22
|
-
@request = request
|
23
|
-
@requested_url = requested_url
|
24
|
-
@requested_params = requested_params
|
25
|
-
@response_hash = response_hash
|
26
|
-
self.replace(response_hash)
|
27
|
-
end
|
28
|
-
|
29
|
-
def data
|
30
|
-
self
|
31
|
-
end
|
32
|
-
alias result data
|
33
|
-
|
34
|
-
def curl_command
|
35
|
-
@curl_command ||= Fanforce::Utils.curl_command(@request.method, @requested_url, @requested_params)
|
36
|
-
end
|
37
|
-
|
38
|
-
def body;
|
39
|
-
@response.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
def current_results; 1 end
|
43
|
-
def total_results; 1 end
|
44
|
-
def current_page; 1 end
|
45
|
-
def total_pages; 1 end
|
46
|
-
def prev_page; nil end
|
47
|
-
def next_page; nil end
|
48
|
-
def prev_page_url; nil end
|
49
|
-
def next_page_url; nil end
|
50
|
-
def code; @response.code end
|
51
|
-
end
|
52
|
-
|
53
|
-
class Fanforce::Api::Results < Array
|
54
|
-
attr_reader :requested_url, :requested_params
|
55
|
-
|
56
|
-
def initialize(response_hash, response, request, requested_url, requested_params)
|
57
|
-
@response = response
|
58
|
-
@request = request
|
59
|
-
@requested_url = requested_url
|
60
|
-
@requested_params = requested_params
|
61
|
-
@response_hash = response_hash
|
62
|
-
self.replace(response_hash[:results])
|
63
|
-
end
|
64
|
-
|
65
|
-
def data
|
66
|
-
self
|
67
|
-
end
|
68
|
-
alias results data
|
69
|
-
|
70
|
-
def curl_command
|
71
|
-
@curl_command ||= Fanforce::Utils.curl_command(@request.method, @requested_url, @requested_params)
|
72
|
-
end
|
73
|
-
|
74
|
-
def body;
|
75
|
-
@response.to_s
|
76
|
-
end
|
77
|
-
|
78
|
-
def current_results
|
79
|
-
@current_results ||= @response_hash[:current_results]
|
80
|
-
end
|
81
|
-
|
82
|
-
def total_results;
|
83
|
-
@total_results ||= @response_hash[:total_results]
|
84
|
-
end
|
85
|
-
|
86
|
-
def current_page;
|
87
|
-
@current_page ||= @response_hash[:current_page]
|
88
|
-
end
|
89
|
-
|
90
|
-
def total_pages;
|
91
|
-
@total_pages ||= @response_hash[:total_pages]
|
92
|
-
end
|
93
|
-
|
94
|
-
def prev_page
|
95
|
-
@prev_page ||= (@request.method == :get and current_page > 1) ? current_page - 1 : nil
|
96
|
-
end
|
97
|
-
|
98
|
-
def next_page
|
99
|
-
@next_page ||= (@request.method == :get and total_pages > current_page) ? current_page + 1 : nil
|
100
|
-
end
|
101
|
-
|
102
|
-
def prev_page_url;
|
103
|
-
@prev_page_url ||= prev_page ? "#{@requested_url}?#{Fanforce::Utils.to_query_string(@requested_params.merge(page: current_page-1))}" : nil
|
104
|
-
end
|
105
|
-
|
106
|
-
def next_page_url;
|
107
|
-
@next_page_url ||= next_page ? "#{@requested_url}?#{Fanforce::Utils.to_query_string(@requested_params.merge(page: current_page+1))}" : nil
|
108
|
-
end
|
109
|
-
def code; @response.code end
|
110
|
-
|
111
|
-
end
|
data/lib/fanforce/api/utils.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'fanforce/utils'
|
2
|
-
|
3
|
-
module Fanforce::Api::Utils
|
4
|
-
include Fanforce::Utils
|
5
|
-
extend Fanforce::Api::Utils
|
6
|
-
def self.included(base) base.extend(self) end
|
7
|
-
|
8
|
-
def valid_fanforce_js_request?(params=@params)
|
9
|
-
return false if !params.is_a?(Hash)
|
10
|
-
return false if is_blank?(params[:fanforce_id]) or is_blank?(params[:api_key])
|
11
|
-
return true
|
12
|
-
end
|
13
|
-
|
14
|
-
def valid_fanforce_request?(params=@params)
|
15
|
-
return false if !params.is_a?(Hash)
|
16
|
-
return false if is_blank?(params[:fanforce_id])
|
17
|
-
return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id])
|
18
|
-
return true
|
19
|
-
end
|
20
|
-
|
21
|
-
def valid_install_request?(params=@params)
|
22
|
-
return false if !params.is_a?(Hash)
|
23
|
-
return false if is_blank?(params[:fanforce_id])
|
24
|
-
return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id])
|
25
|
-
return false if is_blank?(params[:api_key])
|
26
|
-
return true
|
27
|
-
end
|
28
|
-
|
29
|
-
def valid_uninstall_request?(params=@params)
|
30
|
-
return false if !params.is_a?(Hash)
|
31
|
-
return false if is_blank?(params[:fanforce_id])
|
32
|
-
return false if is_blank?(params[:app_id]) and is_blank?(params[:behavior_plugin_id]) and is_blank?(params[:plugin_id]) and is_blank?(params[:widget_id])
|
33
|
-
return false if is_blank?(params[:api_key])
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
|
37
|
-
def remove_nil_values(hash)
|
38
|
-
hash.clone.delete_if {|k,v| v.nil? }
|
39
|
-
end
|
40
|
-
|
41
|
-
def collect_known_params(params)
|
42
|
-
params = params.symbolize_keys
|
43
|
-
if is_present?(params[:app_id])
|
44
|
-
addon_type = :app
|
45
|
-
addon_id = params[:app_id]
|
46
|
-
elsif is_present?(params[:behavior_plugin_id])
|
47
|
-
addon_type = :plugin
|
48
|
-
addon_id = params[:behavior_plugin_id]
|
49
|
-
elsif is_present?(params[:plugin_id])
|
50
|
-
addon_type = :plugin
|
51
|
-
addon_id = params[:plugin_id]
|
52
|
-
elsif is_present?(params[:widget_id])
|
53
|
-
addon_type = :widget
|
54
|
-
addon_id = params[:widget_id]
|
55
|
-
end
|
56
|
-
remove_nil_values(:"#{addon_type}_id" => params[:"#{addon_type}_id"], addon_type: addon_type, addon_id: addon_id, fanforce_id: params[:fanforce_id], fanforce_slug: params[:fanforce_slug], api_key: params[:api_key], session_id: params[:session_id])
|
57
|
-
end
|
58
|
-
|
59
|
-
def remove_internal_params(params)
|
60
|
-
params.clone.delete_if { |k,v| [:app_id, :behavior_plugin_id, :plugin_id, :widget_id, :addon_type, :addon_id, :fanforce_id, :fanforce_slug, :api_key].include? k }
|
61
|
-
end
|
62
|
-
|
63
|
-
def remove_sensitive_params(params)
|
64
|
-
params.clone.delete_if { |k,v| [:api_key].include? k }
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/lib/fanforce/api/version.rb
DELETED
data/test/fanforce_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
|
4
|
-
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
require 'fanforce'
|
6
|
-
|
7
|
-
describe Fanforce do
|
8
|
-
|
9
|
-
it "should test if var is blank" do
|
10
|
-
assert Fanforce.is_blank?(nil)
|
11
|
-
assert !Fanforce.is_blank?("value")
|
12
|
-
|
13
|
-
ff = Fanforce.new
|
14
|
-
assert ff.is_blank?(nil)
|
15
|
-
assert !ff.is_blank?("value")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should create new instance of fanforce with api_key" do
|
19
|
-
Fanforce.new('13d90b01-6df7-4618-881c-c79320a0dc21')
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|