driftrock-service 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/driftrock-service/driftrock_api.rb +3 -15
- data/lib/driftrock-service/driftrock_app.rb +1 -2
- data/lib/driftrock-service/driftrock_model/admin/driftrock_app.rb +14 -0
- data/lib/driftrock-service/driftrock_model/channel.rb +1 -0
- data/lib/driftrock-service/driftrock_model/driftrock_app.rb +2 -7
- data/lib/driftrock-service/driftrock_model/visitor/driftrock_app.rb +13 -0
- data/lib/driftrock-service/driftrock_model.rb +31 -23
- data/lib/driftrock-service/version.rb +1 -1
- data/lib/driftrock-service.rb +11 -1
- metadata +48 -44
- data/lib/driftrock-service/api/admin.rb +0 -23
@@ -12,13 +12,13 @@ module Driftrock::Service
|
|
12
12
|
def self.set_instance(instance)
|
13
13
|
@instance = instance
|
14
14
|
end
|
15
|
+
|
15
16
|
def self.instance
|
16
17
|
@instance
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.website_api(user, company)
|
20
21
|
api = new(user, company)
|
21
|
-
require_module_with_dir :driftrock_model
|
22
22
|
api.extend(Driftrock::Service::Api::Website)
|
23
23
|
api
|
24
24
|
end
|
@@ -29,10 +29,8 @@ module Driftrock::Service
|
|
29
29
|
api
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.admin_api
|
33
|
-
|
34
|
-
api.extend(Driftrock::Service::Api::Admin)
|
35
|
-
api
|
32
|
+
def self.admin_api(user)
|
33
|
+
new(user)
|
36
34
|
end
|
37
35
|
|
38
36
|
def self.puller_api
|
@@ -41,15 +39,5 @@ module Driftrock::Service
|
|
41
39
|
api
|
42
40
|
end
|
43
41
|
|
44
|
-
private
|
45
|
-
def self.require_module_with_dir(module_name)
|
46
|
-
require "driftrock-service/#{module_name}"
|
47
|
-
folder_glob = File.join(
|
48
|
-
File.dirname(__FILE__), module_name.to_s, *%w[** *.rb])
|
49
|
-
Dir[folder_glob].each do |file|
|
50
|
-
require file
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
42
|
end
|
55
43
|
end
|
@@ -8,8 +8,7 @@ module Driftrock::Service
|
|
8
8
|
token = params[:token]
|
9
9
|
expected_token = token_for(timestamp, company_id)
|
10
10
|
if token != expected_token
|
11
|
-
redirect_to Driftrock::Service::Config.website_location+
|
12
|
-
"?unauthorised=true"
|
11
|
+
redirect_to Driftrock::Service::Config.website_location + "?unauthorised=true"
|
13
12
|
else
|
14
13
|
session[:user_id] = params[:user_id]
|
15
14
|
session[:company_id] = params[:company_id]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Driftrock
|
2
|
+
module Admin
|
3
|
+
module DriftrockModel
|
4
|
+
class DriftrockApp
|
5
|
+
include ::Driftrock::Service::DriftrockModel
|
6
|
+
set_api_path "/admin/apps"
|
7
|
+
|
8
|
+
def self.update(id, app_data)
|
9
|
+
put_to_api_method.call("/#{id}", app_data)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,10 +2,6 @@ module Driftrock::Service::DriftrockModel
|
|
2
2
|
class DriftrockApp
|
3
3
|
include Driftrock::Service::DriftrockModel
|
4
4
|
set_api_path "/dashboard_api/driftrock_app"
|
5
|
-
attr_reader :id, :name, :description, :long_description, :visible, :active,
|
6
|
-
:logo, :url, :salt, :app_id, :api_token, :requires_twitter_data,
|
7
|
-
:requires_facebook_data, :requires_adwords_data,
|
8
|
-
:requires_conversion_data, :requires_user_data, :user_has_activated
|
9
5
|
|
10
6
|
def activate
|
11
7
|
post_to_api_method.call("/#{id}/activate")
|
@@ -54,9 +50,8 @@ module Driftrock::Service::DriftrockModel
|
|
54
50
|
new(object_hash)
|
55
51
|
end
|
56
52
|
|
57
|
-
def self.
|
58
|
-
array_of_app_hashes = get_from_api_method.call("/
|
59
|
-
'/dashboard_api/visitor')
|
53
|
+
def self.all_for_current_user
|
54
|
+
array_of_app_hashes = get_from_api_method.call("/apps_for_current_user")
|
60
55
|
array_of_app_hashes.map do |app_hash|
|
61
56
|
app_hash.symbolize_keys!
|
62
57
|
new(app_hash)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Driftrock::Service::DriftrockModel
|
2
|
-
|
2
|
+
|
3
|
+
module DependencyInjection
|
3
4
|
def set_post_to_api_method(method)
|
4
5
|
@post_to_api_method = method
|
5
6
|
end
|
@@ -7,7 +8,7 @@ module Driftrock::Service::DriftrockModel
|
|
7
8
|
def set_put_to_api_method(method)
|
8
9
|
@put_to_api_method = method
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
def set_get_from_api_method(method)
|
12
13
|
@get_from_api_method = method
|
13
14
|
end
|
@@ -21,36 +22,41 @@ module Driftrock::Service::DriftrockModel
|
|
21
22
|
@put_to_api_method ||= self.public_method(:model_put)
|
22
23
|
@put_to_api_method
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def get_from_api_method
|
26
27
|
@get_from_api_method ||= self.public_method(:model_get)
|
27
28
|
@get_from_api_method
|
28
29
|
end
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def api_path
|
35
|
-
@api_path ||= "/"
|
36
|
-
@api_path
|
37
|
-
end
|
38
|
-
|
39
|
-
def find(id)
|
32
|
+
module ActiveRecordSimulator
|
33
|
+
def find(id)
|
40
34
|
object_hash = get_from_api_method.call("/#{id}")
|
41
|
-
new(object_hash)
|
42
|
-
end
|
35
|
+
new(object_hash)
|
36
|
+
end
|
43
37
|
|
44
|
-
def all
|
45
|
-
object_arr = get_from_api_method.call("/")
|
46
|
-
object_arr.map do |object_hash|
|
38
|
+
def all
|
39
|
+
object_arr = get_from_api_method.call("/")
|
40
|
+
object_arr.map do |object_hash|
|
47
41
|
new(object_hash)
|
48
|
-
end
|
42
|
+
end
|
49
43
|
end
|
50
44
|
|
51
45
|
def create(data)
|
52
46
|
post_to_api_method.call("/new", data)
|
53
47
|
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module ClassMethods
|
51
|
+
|
52
|
+
def set_api_path(path)
|
53
|
+
@api_path = path
|
54
|
+
end
|
55
|
+
|
56
|
+
def api_path
|
57
|
+
@api_path ||= "/"
|
58
|
+
@api_path
|
59
|
+
end
|
54
60
|
|
55
61
|
def model_post(path, opts={}, root_path=api_path)
|
56
62
|
post(root_path+path, opts)
|
@@ -64,10 +70,6 @@ module Driftrock::Service::DriftrockModel
|
|
64
70
|
get(root_path+path, opts)
|
65
71
|
end
|
66
72
|
|
67
|
-
def model_name
|
68
|
-
self.to_s.gsub(/.*\:\:/, "").downcase
|
69
|
-
end
|
70
|
-
|
71
73
|
end
|
72
74
|
|
73
75
|
def initialize(object_hash)
|
@@ -78,11 +80,15 @@ module Driftrock::Service::DriftrockModel
|
|
78
80
|
end
|
79
81
|
object_hash.each do |(key, value)|
|
80
82
|
instance_variable_set(("@"+key.to_s).to_sym, value)
|
83
|
+
instance_var_reader = lambda { instance_variable_get("@" + key.to_s) }
|
84
|
+
self.class.send(:define_method, key.to_s, instance_var_reader)
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
88
|
|
85
89
|
def self.included(base)
|
90
|
+
base.extend DependencyInjection
|
91
|
+
base.extend ActiveRecordSimulator
|
86
92
|
base.extend ClassMethods
|
87
93
|
base.extend Driftrock::Service::Api
|
88
94
|
base.send(:include, Driftrock::Service::Api)
|
@@ -91,9 +97,11 @@ module Driftrock::Service::DriftrockModel
|
|
91
97
|
def get_from_api_method
|
92
98
|
self.class.get_from_api_method
|
93
99
|
end
|
100
|
+
|
94
101
|
def post_to_api_method
|
95
102
|
self.class.post_to_api_method
|
96
103
|
end
|
104
|
+
|
97
105
|
def put_to_api_method
|
98
106
|
self.class.put_to_api_method
|
99
107
|
end
|
data/lib/driftrock-service.rb
CHANGED
@@ -4,7 +4,6 @@ require "driftrock-service/connector"
|
|
4
4
|
require "driftrock-service/api"
|
5
5
|
require "driftrock-service/api/website"
|
6
6
|
require "driftrock-service/api/visitor"
|
7
|
-
require "driftrock-service/api/admin"
|
8
7
|
require "driftrock-service/api/data"
|
9
8
|
require "driftrock-service/api/puller"
|
10
9
|
require "driftrock-service/errors/driftrock_error"
|
@@ -12,6 +11,17 @@ require "driftrock-service/driftrock_logger"
|
|
12
11
|
require "driftrock-service/driftrock_app"
|
13
12
|
require "driftrock-service/driftrock_api"
|
14
13
|
|
14
|
+
require "driftrock-service/driftrock_model"
|
15
|
+
require "driftrock-service/driftrock_model/driftrock_app"
|
16
|
+
|
17
|
+
def require_all(directory_location)
|
18
|
+
folder_glob = File.join(File.dirname(__FILE__), directory_location, *%w[** *.rb])
|
19
|
+
Dir[folder_glob].each do |file|
|
20
|
+
require file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require_all "driftrock-service/driftrock_model"
|
15
25
|
|
16
26
|
module Driftrock
|
17
27
|
module Service
|
metadata
CHANGED
@@ -1,49 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: driftrock-service
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5
|
4
5
|
prerelease:
|
5
|
-
version: 0.4.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Max
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: httparty
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: rspec
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
30
33
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
35
38
|
type: :development
|
36
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
37
46
|
description: Gem for talking to the driftrock api
|
38
|
-
email:
|
47
|
+
email:
|
39
48
|
- max.dupenois@forward.co.uk
|
40
49
|
executables: []
|
41
|
-
|
42
50
|
extensions: []
|
43
|
-
|
44
51
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
52
|
+
files:
|
47
53
|
- .gitignore
|
48
54
|
- .rspec
|
49
55
|
- Gemfile
|
@@ -53,7 +59,6 @@ files:
|
|
53
59
|
- driftrock-service.gemspec
|
54
60
|
- lib/driftrock-service.rb
|
55
61
|
- lib/driftrock-service/api.rb
|
56
|
-
- lib/driftrock-service/api/admin.rb
|
57
62
|
- lib/driftrock-service/api/data.rb
|
58
63
|
- lib/driftrock-service/api/puller.rb
|
59
64
|
- lib/driftrock-service/api/visitor.rb
|
@@ -64,11 +69,13 @@ files:
|
|
64
69
|
- lib/driftrock-service/driftrock_app.rb
|
65
70
|
- lib/driftrock-service/driftrock_logger.rb
|
66
71
|
- lib/driftrock-service/driftrock_model.rb
|
72
|
+
- lib/driftrock-service/driftrock_model/admin/driftrock_app.rb
|
67
73
|
- lib/driftrock-service/driftrock_model/channel.rb
|
68
74
|
- lib/driftrock-service/driftrock_model/channel_type.rb
|
69
75
|
- lib/driftrock-service/driftrock_model/company.rb
|
70
76
|
- lib/driftrock-service/driftrock_model/driftrock_app.rb
|
71
77
|
- lib/driftrock-service/driftrock_model/user.rb
|
78
|
+
- lib/driftrock-service/driftrock_model/visitor/driftrock_app.rb
|
72
79
|
- lib/driftrock-service/errors/driftrock_error.rb
|
73
80
|
- lib/driftrock-service/version.rb
|
74
81
|
- spec/models/channel_spec.rb
|
@@ -80,32 +87,29 @@ files:
|
|
80
87
|
- spec/website_spec_helper.rb
|
81
88
|
homepage: https://github.com/forward/driftrock-service
|
82
89
|
licenses: []
|
83
|
-
|
84
90
|
post_install_message:
|
85
91
|
rdoc_options: []
|
86
|
-
|
87
|
-
require_paths:
|
92
|
+
require_paths:
|
88
93
|
- lib
|
89
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
95
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version:
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
101
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
version:
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
101
106
|
requirements: []
|
102
|
-
|
103
107
|
rubyforge_project:
|
104
108
|
rubygems_version: 1.8.24
|
105
109
|
signing_key:
|
106
110
|
specification_version: 3
|
107
111
|
summary: Maintains the api endpoints and the calls to them with authorisation, etc.
|
108
|
-
test_files:
|
112
|
+
test_files:
|
109
113
|
- spec/models/channel_spec.rb
|
110
114
|
- spec/models/channel_type_spec.rb
|
111
115
|
- spec/models/company_spec.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Driftrock
|
2
|
-
module Service
|
3
|
-
module Api
|
4
|
-
module Admin
|
5
|
-
include Driftrock::Service::Api
|
6
|
-
|
7
|
-
module URLs
|
8
|
-
BASE = '/admin'
|
9
|
-
APPS = BASE+'/apps'
|
10
|
-
end
|
11
|
-
|
12
|
-
def all_apps
|
13
|
-
get(URLs::APPS)
|
14
|
-
end
|
15
|
-
|
16
|
-
def update_app(id, app_data)
|
17
|
-
put(URLs::APPS + "/#{id}", app_data)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|