driftrock-service 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -13,14 +13,6 @@ module Driftrock
13
13
  get(ENDPOINT+'/query', {query: query}.merge(opts))
14
14
  end
15
15
 
16
- def driftrock_app_status
17
- render text: "OK"
18
- end
19
-
20
- def driftrock_logout
21
- reset_session
22
- redirect_to Config.website_location+"/logout"
23
- end
24
16
  end
25
17
  end
26
18
  end
@@ -7,88 +7,15 @@ module Driftrock
7
7
  module URLs
8
8
  BASE = '/dashboard_api'
9
9
  USERS = BASE+'/user'
10
+ COMPANIES= BASE+'/companies'
10
11
  CHANNELS = BASE+'/channel'
11
12
  APPS = BASE+'/driftrock_app'
12
13
  end
13
14
 
14
- def list_apps(opts = {})
15
- get(URLs::APPS+"/", opts)
16
- end
17
-
18
- def get_app(app_id, opts ={})
19
- get(URLs::APPS+"/#{app_id}", opts)
20
- end
21
-
22
- def get_app_by_string_app_id(app_id, opts ={})
23
- get(URLs::APPS+"/#{app_id}/by_app_id", opts)
24
- end
25
-
26
15
  def add_twitter_details(username, password)
27
16
  post(URLs::CHANNELS+"/temp/connect_twitter", {username: username, password: password})
28
17
  end
29
18
 
30
- def auth_token(app_id, timestamp, opts={})
31
- response = post(URLs::APPS+"/#{app_id}/auth_token",
32
- {timestamp: timestamp}.merge(opts))
33
- response['token']
34
- end
35
-
36
- def activate_app(app_id, opts={})
37
- post(URLs::APPS+"/#{app_id}/activate", opts)
38
- end
39
-
40
- def channel_types
41
- get(URLs::CHANNELS+"/types")
42
- end
43
-
44
- def add_channel(channel_name, channel_data)
45
- post(URLs::CHANNELS+"/#{channel_name}", channel_data)
46
- end
47
-
48
- def get_channel(channel_name)
49
- get(URLs::CHANNELS+"/#{channel_name}")
50
- end
51
-
52
- def add_profile_for_channel(channel_name, profile_id)
53
- post(URLs::CHANNELS+"/#{channel_name}/profile", {profile_id: profile_id})
54
- end
55
-
56
- def new_token_for_channel(channel_name, token)
57
- put(URLs::CHANNELS+"/#{channel_name}/profile", token)
58
- end
59
-
60
- def driftrock_login(validation_data)
61
- post(URLs::USERS+"/login", validation_data)
62
- end
63
-
64
- def new_account(user_data)
65
- post(URLs::USERS+"/new", user_data)
66
- end
67
-
68
- def add_company(company_data)
69
- post(URLs::USERS+"/company", company_data)
70
- end
71
-
72
- def get_user(user_session_id)
73
- get(URLs::USERS+"/#{user_session_id}")
74
- end
75
-
76
- def get_company(company_id)
77
- get(URLs::USERS+"/company/#{company_id}")
78
- end
79
-
80
- def get_companies
81
- get(URLs::USERS+"/companies")
82
- end
83
-
84
- def user_admin?(user_session_id)
85
- response = get(URLs::USERS+"/#{user_session_id}/is_admin")
86
- response['is_admin'] =~ /true/
87
- end
88
-
89
- def new_company(company_data)
90
- post(URLs::COMPANIES+"/new", company_data)
91
- end
92
19
  end
93
20
  end
94
21
  end
@@ -1,6 +1,8 @@
1
1
  module Driftrock
2
2
  module Service
3
3
  module Api
4
+
5
+
4
6
  def get(url, opts={})
5
7
  api_request(opts) do |user_id, company_id|
6
8
  Driftrock::Service::Connector.get_from_api(
@@ -25,12 +27,19 @@ module Driftrock
25
27
  end
26
28
  end
27
29
 
30
+ def symbolise_keys(hash)
31
+ hash.reduce({}) do |new_hash, (key, value)|
32
+ new_hash[key.to_sym] = value
33
+ new_hash
34
+ end
35
+ end
36
+
28
37
  private
29
38
  def api_request(opts)
30
39
  user_id, company_id = nil
31
- if respond_to?(:session)
32
- user_id = session[:user_id] if session && session[:user_id]
33
- company_id = session[:company_id] if session && session[:company_id]
40
+ if DriftrockApi.instance
41
+ user_id = DriftrockApi.instance.current_user_id
42
+ company_id = DriftrockApi.instance.current_company_id
34
43
  end
35
44
  user_id = opts[:user_id] if opts[:user_id]
36
45
  company_id = opts[:company_id] if opts[:company_id]
@@ -1,57 +1,85 @@
1
1
  module Driftrock
2
2
  module Service
3
- class Config < Struct.new(:salt, :website_location, :status_location,
3
+ class Config < Struct.new(:salt, :environment, :status_location,
4
4
  :status_action,
5
- :logout_action, :log_location,:log_level,:base_url,
5
+ :logout_action, :log_location,:log_level,
6
6
  :app_id,:api_token)
7
7
  private_class_method :new
8
8
 
9
- def self.base_url
10
- @config.base_url
9
+ def self.api_location
10
+ if config_properties.environment == :production
11
+ "https://driftrock-user-details-api.herokuapp.com"
12
+ else
13
+ "http://localhost:9393"
14
+ end
11
15
  end
12
16
 
13
17
  def self.salt
14
- @config.salt
18
+ config_properties.salt
15
19
  end
16
20
 
17
21
  def self.api_token
18
- @config.api_token
22
+ config_properties.api_token
19
23
  end
20
24
 
21
25
  def self.app_id
22
- @config.app_id
26
+ config_properties.app_id
23
27
  end
24
28
 
25
29
  def self.log_level
26
- @config.log_level
30
+ config_properties.log_level
27
31
  end
28
32
 
29
33
  def self.log_location
30
- @config.log_location
34
+ config_properties.log_location
31
35
  end
32
36
 
33
37
  def self.website_location
34
- @config.website_location
38
+ if config_properties.environment == :production
39
+ "http://www.driftrock.com"
40
+ else
41
+ "http://localhost:3000"
42
+ end
43
+ end
44
+
45
+ def self.environment
46
+ config_properties.enviroment
35
47
  end
36
48
 
37
49
  def self.init
38
- config = new
39
- config.log_level = DriftrockLogger::Levels::ALL
40
- config.log_location = STDOUT
41
- config.website_location = "http://www.driftrock.com"
42
- config.status_action = "application#driftrock_app_status"
43
- config.logout_action = "application#driftrock_logout"
44
- yield(config)
45
- config.base_url.gsub(/\/$/, "") if config.base_url
46
- if defined?(Rails) && config.app_id
50
+ yield(config_properties)
51
+ if defined?(Rails) && config_properties.app_id
52
+ status_action = config_properties.status_action
53
+ logout_action = config_properties.logout_action
47
54
  Rails.application.routes.prepend do
48
- get 'driftrock_app_status' => config.status_action
49
- get 'driftrock_logout' => config.logout_action
55
+ get 'driftrock_app_status' => status_action
56
+ get 'driftrock_logout' => logout_action
50
57
  end
51
58
  end
52
- @config = config
53
59
  end
54
-
60
+
61
+ private
62
+ def self.default
63
+ default = new
64
+ default.log_level = DriftrockLogger::Levels::ALL
65
+ default.log_location = STDOUT
66
+ default.status_action = "application#driftrock_app_status"
67
+ default.logout_action = "application#driftrock_logout"
68
+ default.environment = if ENV['RACK_ENV']
69
+ ENV['RACK_ENV'].to_sym
70
+ elsif ENV['RAILS_ENV']
71
+ ENV['RAILS_ENV'].to_sym
72
+ elsif defined?(Rails)
73
+ Rails.env
74
+ else
75
+ :test
76
+ end
77
+ default
78
+ end
79
+ def self.config_properties
80
+ @config ||= default
81
+ @config
82
+ end
55
83
  end
56
84
  end
57
85
  end
@@ -5,7 +5,7 @@ module Driftrock
5
5
 
6
6
  def build_url_for_driftrock(url)
7
7
  url = "/"+url if url !~ /^\/.*/
8
- Driftrock::Service::Config.base_url+url
8
+ Driftrock::Service::Config.api_location+url
9
9
  end
10
10
 
11
11
  def post_to_api(url, user_id, company_id, data)
@@ -0,0 +1,55 @@
1
+ module Driftrock::Service
2
+ class DriftrockApi
3
+ private_class_method :new
4
+ attr_reader :current_user_id, :current_company_id
5
+
6
+ def initialize(user=nil, company=nil)
7
+ @current_user_id = user if user
8
+ @current_company_id = company if company
9
+ DriftrockApi.set_instance(self)
10
+ end
11
+
12
+ def self.set_instance(instance)
13
+ @instance = instance
14
+ end
15
+ def self.instance
16
+ @instance
17
+ end
18
+
19
+ def self.website_api(user, company)
20
+ api = new(user, company)
21
+ require_module_with_dir :driftrock_model
22
+ api.extend(Driftrock::Service::Api::Website)
23
+ api
24
+ end
25
+
26
+ def self.data_api(user, company)
27
+ api = new(user, company)
28
+ api.extend(Driftrock::Service::Api::Data)
29
+ api
30
+ end
31
+
32
+ def self.admin_api
33
+ api = new
34
+ api.extend(Driftrock::Service::Api::Admin)
35
+ api
36
+ end
37
+
38
+ def self.puller_api
39
+ api = new
40
+ api.extend(Driftrock::Service::Api::Puller)
41
+ api
42
+ end
43
+
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
+ end
55
+ end
@@ -16,6 +16,15 @@ module Driftrock::Service
16
16
  end
17
17
  end
18
18
 
19
+ def driftrock_app_status
20
+ render text: "OK"
21
+ end
22
+
23
+ def driftrock_logout
24
+ reset_session
25
+ redirect_to Config.website_location+"/logout"
26
+ end
27
+
19
28
  def token_for(timestamp, company_id)
20
29
  OpenSSL::Digest::SHA1.hexdigest(
21
30
  [timestamp,Driftrock::Service::Config.salt,company_id].join(":")
@@ -0,0 +1,54 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class Channel
3
+ include Driftrock::Service::DriftrockModel
4
+ set_api_path '/dashboard_api/channel'
5
+ attr_reader :id, :profile_id, :company,
6
+ :token, :refresh_token, :token_expiry,
7
+ :expires_in, :channel_type, :next_step_action
8
+ attr_accessor :channel_type
9
+
10
+ def set_profile_id(profile_id)
11
+ response = post_to_api_method.call(
12
+ "/#{channel_type.name}/profile", {profile_id: profile_id}
13
+ )
14
+ success = response['status'] == 'success'
15
+ @profile_id = profile_id if success
16
+ success
17
+ end
18
+
19
+ def update_token(token_data)
20
+ response = put_to_api_method.call(
21
+ "/#{channel_type.name}/profile", token_data
22
+ )
23
+ success = response['status'] == 'success'
24
+ if success
25
+ @token = token_data[:token]
26
+ @token_expiry = token_data[:token_expiry]
27
+ @expires_in = token_data[:expires_in]
28
+ end
29
+ success
30
+ end
31
+
32
+ def self.create_by_channel_type(type_name, channel_data)
33
+ ChannelType.find_by_name(type_name).create_channel(channel_data)
34
+ end
35
+
36
+ def self.find_by_channel_type_name(name)
37
+ object_hsh = get_from_api_method.call(
38
+ "/#{name}"
39
+ )
40
+ channel = new(object_hsh)
41
+ channel.channel_type = ChannelType.find_by_name(name)
42
+ channel
43
+ end
44
+
45
+ def self.channel_types
46
+ object_arr = get_from_api_method.call(
47
+ "/types"
48
+ )
49
+ object_arr.map do |object_hash|
50
+ ChannelType.new(object_hash)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,24 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class ChannelType
3
+ include Driftrock::Service::DriftrockModel
4
+ set_api_path '/dashboard_api/channel'
5
+ attr_reader :id, :name, :channel_status, :next_step_action
6
+
7
+ def create_channel(channel_data)
8
+ response = post_to_api_method.call(
9
+ "/#{name}", channel_data
10
+ )
11
+ channel = Channel.new(channel_data)
12
+ channel.channel_type = self
13
+ channel
14
+ end
15
+
16
+ def self.find_by_name(name)
17
+ object_hash = get_from_api_method.call(
18
+ "/#{name}/by_name"
19
+ )
20
+ new(object_hash)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class Company
3
+ include Driftrock::Service::DriftrockModel
4
+ set_api_path "/dashboard_api/company"
5
+
6
+ attr_reader :id, :name
7
+
8
+ def add_user(user)
9
+ response = post_to_api_method.call(
10
+ '/add_user', {user_to_add_id: user.id}
11
+ )
12
+ response['status'] == 'success'
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,68 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class DriftrockApp
3
+ include Driftrock::Service::DriftrockModel
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
+
10
+ def activate
11
+ post_to_api_method.call("/#{id}/activate")
12
+ end
13
+
14
+ def auth_token(timestamp)
15
+ response = post_to_api_method.call(
16
+ "/#{id}/auth_token",
17
+ {timestamp: timestamp})
18
+ response['token']
19
+ end
20
+
21
+ def show_url
22
+ timestamp = DateTime.now
23
+ token = auth_token(timestamp)
24
+ query_str = {
25
+ timestamp: timestamp,
26
+ company_id: ::Driftrock::Service::DriftrockApi.instance.current_company_id,
27
+ token: token,
28
+ user_id: ::Driftrock::Service::DriftrockApi.instance.current_user_id
29
+ }.to_query
30
+ url+"?"+query_str
31
+ end
32
+
33
+ def logout_url
34
+ url+"/driftrock_logout"
35
+ end
36
+
37
+ def status_url
38
+ url+"/driftrock_app_status"
39
+ end
40
+
41
+ def status_check(http_method = HTTParty.public_method(:get))
42
+ status = :ok
43
+ begin
44
+ status_text = http_method.call(status_url)
45
+ status = :not_ok if status_text.strip != "OK"
46
+ rescue Errno::ECONNREFUSED => e
47
+ status = :not_available
48
+ end
49
+ status
50
+ end
51
+
52
+ def self.find_by_app_id(app_id)
53
+ object_hash = get_from_api_method.call("/#{app_id}/by_app_id")
54
+ new(object_hash)
55
+ end
56
+
57
+ def self.all_apps
58
+ array_of_app_hashes = get_from_api_method.call("/apps", {},
59
+ '/dashboard_api/visitor')
60
+ array_of_app_hashes = array_of_app_hashes.symbolize_keys[:apps]
61
+ array_of_app_hashes.map do |app_hash|
62
+ app_hash.symbolize_keys!
63
+ new(app_hash)
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,53 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class User
3
+ include Driftrock::Service::DriftrockModel
4
+ set_api_path "/dashboard_api/user"
5
+ attr_reader :id, :session_id, :first_name, :last_name, :email
6
+
7
+ def admin?
8
+ @check_admin
9
+ end
10
+
11
+ def self.login(validation_data)
12
+ post_to_api_method.call("/login", validation_data)
13
+ #Get session id
14
+ end
15
+
16
+ def self.find_by_email(email)
17
+ object_hash = get_from_api_method.call("/#{email}/by_email")
18
+ new(object_hash)
19
+ end
20
+
21
+ def self.find_by_session_id(session_id)
22
+ object_hash = get_from_api_method.call("/#{session_id}")
23
+ new(object_hash)
24
+ end
25
+
26
+
27
+ def user_admin?
28
+ response = get_from_api_method.call("/#{session_id}/is_admin")
29
+ response['is_admin'] =~ /true/
30
+ end
31
+
32
+ def add_company(company_data)
33
+ post_to_api_method.call("/company", company_data.merge({
34
+ user_id: session_id
35
+ }))
36
+ end
37
+
38
+ def company(company_id)
39
+ company_hsh = get_from_api_method.call("/company/#{company_id}",
40
+ {user_id: session_id})
41
+ Company.new(company_hsh)
42
+ end
43
+
44
+ def companies
45
+ company_arr = get_from_api_method.call("/companies",
46
+ {user_id: session_id})
47
+ company_arr.map do |company_hash|
48
+ Company.new(company_hash)
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,101 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ module ClassMethods
3
+ def set_post_to_api_method(method)
4
+ @post_to_api_method = method
5
+ end
6
+
7
+ def set_put_to_api_method(method)
8
+ @put_to_api_method = method
9
+ end
10
+
11
+ def set_get_from_api_method(method)
12
+ @get_from_api_method = method
13
+ end
14
+
15
+ def post_to_api_method
16
+ @post_to_api_method ||= self.public_method(:model_post)
17
+ @post_to_api_method
18
+ end
19
+
20
+ def put_to_api_method
21
+ @put_to_api_method ||= self.public_method(:model_put)
22
+ @put_to_api_method
23
+ end
24
+
25
+ def get_from_api_method
26
+ @get_from_api_method ||= self.public_method(:model_get)
27
+ @get_from_api_method
28
+ end
29
+
30
+ def set_api_path(path)
31
+ @api_path = path
32
+ end
33
+
34
+ def api_path
35
+ @api_path ||= "/"
36
+ @api_path
37
+ end
38
+
39
+ def find(id)
40
+ object_hash = get_from_api_method.call("/#{id}")
41
+ new(object_hash)
42
+ end
43
+
44
+ def all
45
+ object_arr = get_from_api_method.call("/")
46
+ object_arr.map do |object_hash|
47
+ new(object_hash)
48
+ end
49
+ end
50
+
51
+ def create(data)
52
+ post_to_api_method.call("/new", data)
53
+ end
54
+
55
+ def model_post(path, opts={}, root_path=api_path)
56
+ post(root_path+path, opts)
57
+ end
58
+
59
+ def model_put(path, opts={}, root_path=api_path)
60
+ put(root_path+path, opts)
61
+ end
62
+
63
+ def model_get(path, opts={}, root_path=api_path)
64
+ get(root_path+path, opts)
65
+ end
66
+
67
+ def model_name
68
+ self.to_s.gsub(/.*\:\:/, "").downcase
69
+ end
70
+
71
+ end
72
+
73
+ def initialize(object_hash)
74
+ if object_hash.respond_to?(:symbolize_keys!)
75
+ object_hash.symbolize_keys!
76
+ else
77
+ symbolise_keys(object_hash)
78
+ end
79
+ object_hash.each do |(key, value)|
80
+ instance_variable_set(("@"+key.to_s).to_sym, value)
81
+ end
82
+ end
83
+
84
+
85
+ def self.included(base)
86
+ base.extend ClassMethods
87
+ base.extend Driftrock::Service::Api
88
+ base.send(:include, Driftrock::Service::Api)
89
+ end
90
+
91
+ def get_from_api_method
92
+ self.class.get_from_api_method
93
+ end
94
+ def post_to_api_method
95
+ self.class.post_to_api_method
96
+ end
97
+ def put_to_api_method
98
+ self.class.put_to_api_method
99
+ end
100
+
101
+ end
@@ -1,5 +1,5 @@
1
1
  module Driftrock
2
2
  module Service
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -10,46 +10,19 @@ require "driftrock-service/api/puller"
10
10
  require "driftrock-service/errors/driftrock_error"
11
11
  require "driftrock-service/driftrock_logger"
12
12
  require "driftrock-service/driftrock_app"
13
+ require "driftrock-service/driftrock_api"
13
14
 
14
15
 
15
16
  module Driftrock
16
17
  module Service
17
18
 
18
19
  module ClassMethods
19
- def acts_as_driftrock_app
20
+ def add_driftrock_app_rails_filters
20
21
  if respond_to?(:before_filter)
21
22
  include Driftrock::Service::DriftrockApp
22
23
  before_filter :authorise, except: :driftrock_app_status
23
24
  end
24
- include Driftrock::Service::Api::Data
25
25
  end
26
-
27
- def acts_as_driftrock_app_model
28
- include Driftrock::Service::Api::Data
29
- extend Driftrock::Service::Api::Data
30
- end
31
-
32
- def acts_as_driftrock_website
33
- include Driftrock::Service::Api::Website
34
- end
35
-
36
- def acts_as_driftrock_website_model
37
- include Driftrock::Service::Api::Website
38
- extend Driftrock::Service::Api::Website
39
- end
40
-
41
- def acts_as_driftrock_website_visitor_model
42
- include Driftrock::Service::Api::Visitor
43
- extend Driftrock::Service::Api::Visitor
44
- end
45
-
46
- def acts_as_driftrock_admin
47
- include Driftrock::Service::Api::Admin
48
- end
49
-
50
- def acts_as_driftrock_puller
51
- include Driftrock::Service::Api::Puller
52
- end
53
26
  end
54
27
 
55
28
  def self.included(base)
@@ -0,0 +1,60 @@
1
+ require 'website_spec_helper'
2
+ describe DriftrockModel::Channel do
3
+ before do
4
+ @post_method = mock(:post)
5
+ @get_method = mock(:get)
6
+ @put_method = mock(:put)
7
+ DriftrockModel::Channel.set_post_to_api_method @post_method
8
+ DriftrockModel::Channel.set_put_to_api_method @put_method
9
+ DriftrockModel::Channel.set_get_from_api_method @get_method
10
+ @test_channel = DriftrockModel::Channel.new({
11
+ id: 1
12
+ })
13
+ @test_channel_type = DriftrockModel::ChannelType.new({
14
+ id: 1,
15
+ name: "google_analytics"
16
+ })
17
+ @test_channel.channel_type = @test_channel_type
18
+ end
19
+
20
+ it "should be able to add a profile id to a channel" do
21
+ @post_method.should_receive(:call).with(
22
+ "/#{@test_channel_type.name}/profile", {profile_id: "test"}).
23
+ and_return({'status' => 'success'})
24
+ @test_channel.set_profile_id("test")
25
+ @test_channel.profile_id.should == "test"
26
+ end
27
+
28
+ it "should be able to get a channel by channel type name" do
29
+ @get_method.should_receive(:call).with(
30
+ "/#{@test_channel_type.name}"
31
+ ).and_return({id: 1})
32
+ channel_type_get = mock(:channel_type_get)
33
+ channel_type_get.should_receive(:call).with(
34
+ "/#{@test_channel_type.name}/by_name"
35
+ ).and_return({id:1, name: "google_analytics"})
36
+ DriftrockModel::ChannelType.set_get_from_api_method(channel_type_get)
37
+ channel =DriftrockModel::Channel.
38
+ find_by_channel_type_name(@test_channel_type.name)
39
+ channel.id.should == 1
40
+ end
41
+
42
+ it "should be able to get all channel types" do
43
+ @get_method.should_receive(:call).with(
44
+ "/types"
45
+ ).and_return([{id: 1, name: "google_analytics"}])
46
+ types = DriftrockModel::Channel.channel_types
47
+ types.size.should == 1
48
+ types.first.name.should == "google_analytics"
49
+ end
50
+
51
+ it "should be able to replace a channel token" do
52
+ tkn = {token: "hello", token_expiry: DateTime.now, expires_in: 3600}
53
+ @put_method.should_receive(:call).with(
54
+ "/#{@test_channel_type.name}/profile", tkn
55
+ ).and_return("status" => "success")
56
+ @test_channel.update_token(tkn)
57
+ @test_channel.token.should == "hello"
58
+ end
59
+
60
+ end
@@ -0,0 +1,17 @@
1
+ require 'website_spec_helper'
2
+ describe DriftrockModel::ChannelType do
3
+ before do
4
+ @post_method = mock(:post)
5
+ @get_method = mock(:get)
6
+ DriftrockModel::Channel.set_post_to_api_method @post_method
7
+ DriftrockModel::Channel.set_get_from_api_method @get_method
8
+ @test_channel = DriftrockModel::Channel.new({
9
+ id: 1
10
+ })
11
+ @test_channel_type = DriftrockModel::ChannelType.new({
12
+ id: 1,
13
+ name: "google_analytics"
14
+ })
15
+ @test_channel.channel_type = @test_channel_type
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require 'website_spec_helper'
2
+
3
+ describe DriftrockModel::Company do
4
+ before do
5
+ @post_method = mock(:post)
6
+ @get_method = mock(:get)
7
+ DriftrockModel::Company.set_post_to_api_method @post_method
8
+ DriftrockModel::Company.set_get_from_api_method @get_method
9
+ @test_company = DriftrockModel::Company.new({id: 1, name: "test"})
10
+ @test_user = DriftrockModel::User.new({id: 1, first_name: "test_user"})
11
+ end
12
+
13
+
14
+ it "should allow the retrieval of a company by its id" do
15
+ @get_method.should_receive(:call).
16
+ with("/1").and_return({id: 1, name: "test"})
17
+ DriftrockModel::Company.find(1).name.should == "test"
18
+ end
19
+
20
+ it "should allow the retrieval of multiple companies" do
21
+ companies = [{id: 1, name: "test"},{id: 2, name: "test2"}]
22
+ @get_method.should_receive(:call).
23
+ with("/").and_return(companies)
24
+ DriftrockModel::Company.all.last.name.should == "test2"
25
+ end
26
+
27
+ it "should allow a user to be added to a company" do
28
+ @post_method.should_receive(:call).
29
+ with("/add_user", {:user_to_add_id=>1}).and_return({'status' => 'success'})
30
+ @test_company.add_user(@test_user).should be_true
31
+ end
32
+
33
+ end
@@ -0,0 +1,16 @@
1
+ require 'website_spec_helper'
2
+ describe DriftrockModel::DriftrockApp do
3
+ before do
4
+ @post_method = mock(:post)
5
+ @get_method = mock(:get)
6
+ DriftrockModel::DriftrockApp.set_post_to_api_method @post_method
7
+ DriftrockModel::DriftrockApp.set_get_from_api_method @get_method
8
+ end
9
+
10
+ it "should be able to get an app by its app_id" do
11
+ @get_method.should_receive(:call).with("/string-app-id/by_app_id").
12
+ and_return({id: 1, name: "test-app"})
13
+ DriftrockModel::DriftrockApp.find_by_app_id("string-app-id").id.should == 1
14
+ end
15
+
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'website_spec_helper'
2
+
3
+ describe DriftrockModel::User do
4
+ before do
5
+ @post_method = mock(:post)
6
+ @get_method = mock(:get)
7
+ DriftrockModel::User.set_post_to_api_method @post_method
8
+ DriftrockModel::User.set_get_from_api_method @get_method
9
+ end
10
+
11
+
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,20 @@
1
1
  require 'driftrock-service'
2
- require File.join(File.dirname(__FILE__), *%w[models administrative_api_test.rb])
2
+ require 'rspec/autorun'
3
+ Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each {|file| require file }
4
+ Dir[File.dirname(__FILE__) + '/builders/*.rb'].each {|file| require file }
3
5
 
4
- Driftrock::Service::Config.init do |config|
5
- config.base_url = "http://localhost:9393"
6
- config.salt = "3kllki3weid9n3rljcw932oknc2ico23nlckno2i3f2on2o4ilknc2il3jp23mn"
7
- config.api_token = "45asf42cwewfwf234/sfw34"
8
- config.app_id = "23df434v34gdfnrnrt/regergw4"
6
+ include Driftrock::Service
7
+
8
+ RSpec.configure do |config|
9
+
10
+ config.before(:suite) do
11
+ end
12
+
13
+ config.before(:each) do
14
+ end
15
+
16
+ config.after(:each) do
17
+ end
18
+
19
+ config.order = "random"
9
20
  end
@@ -0,0 +1,2 @@
1
+ require 'spec_helper'
2
+ DriftrockApi.website_api("test-user-id", "test-company=id")
metadata CHANGED
@@ -1,56 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: driftrock-service
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.3
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.4.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Max
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-06-04 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: httparty
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
17
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
31
27
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
28
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
46
37
  description: Gem for talking to the driftrock api
47
- email:
38
+ email:
48
39
  - max.dupenois@forward.co.uk
49
40
  executables: []
41
+
50
42
  extensions: []
43
+
51
44
  extra_rdoc_files: []
52
- files:
45
+
46
+ files:
53
47
  - .gitignore
48
+ - .rspec
54
49
  - Gemfile
55
50
  - LICENSE.txt
56
51
  - README.md
@@ -65,38 +60,56 @@ files:
65
60
  - lib/driftrock-service/api/website.rb
66
61
  - lib/driftrock-service/config.rb
67
62
  - lib/driftrock-service/connector.rb
63
+ - lib/driftrock-service/driftrock_api.rb
68
64
  - lib/driftrock-service/driftrock_app.rb
69
65
  - lib/driftrock-service/driftrock_logger.rb
66
+ - lib/driftrock-service/driftrock_model.rb
67
+ - lib/driftrock-service/driftrock_model/channel.rb
68
+ - lib/driftrock-service/driftrock_model/channel_type.rb
69
+ - lib/driftrock-service/driftrock_model/company.rb
70
+ - lib/driftrock-service/driftrock_model/driftrock_app.rb
71
+ - lib/driftrock-service/driftrock_model/user.rb
70
72
  - lib/driftrock-service/errors/driftrock_error.rb
71
73
  - lib/driftrock-service/version.rb
72
- - spec/administrative_api_spec.rb
73
- - spec/models/administrative_api_test.rb
74
+ - spec/models/channel_spec.rb
75
+ - spec/models/channel_type_spec.rb
76
+ - spec/models/company_spec.rb
77
+ - spec/models/driftrock_app_spec.rb
78
+ - spec/models/user_spec.rb
74
79
  - spec/spec_helper.rb
80
+ - spec/website_spec_helper.rb
75
81
  homepage: https://github.com/forward/driftrock-service
76
82
  licenses: []
83
+
77
84
  post_install_message:
78
85
  rdoc_options: []
79
- require_paths:
86
+
87
+ require_paths:
80
88
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
89
+ required_ruby_version: !ruby/object:Gem::Requirement
82
90
  none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
87
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
96
  none: false
89
- requirements:
90
- - - ! '>='
91
- - !ruby/object:Gem::Version
92
- version: '0'
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
93
101
  requirements: []
102
+
94
103
  rubyforge_project:
95
104
  rubygems_version: 1.8.24
96
105
  signing_key:
97
106
  specification_version: 3
98
107
  summary: Maintains the api endpoints and the calls to them with authorisation, etc.
99
- test_files:
100
- - spec/administrative_api_spec.rb
101
- - spec/models/administrative_api_test.rb
108
+ test_files:
109
+ - spec/models/channel_spec.rb
110
+ - spec/models/channel_type_spec.rb
111
+ - spec/models/company_spec.rb
112
+ - spec/models/driftrock_app_spec.rb
113
+ - spec/models/user_spec.rb
102
114
  - spec/spec_helper.rb
115
+ - spec/website_spec_helper.rb
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AdministrativeApiTest do
4
- it "should error without a user and session id" do
5
- #Assume for the sake of testing there's at least one app
6
- lambda{
7
- AdministrativeApiTest.new.list_apps
8
- }.should raise_error(Driftrock::Errors::DriftrockError)
9
- end
10
-
11
- end
@@ -1,8 +0,0 @@
1
- class AdministrativeApiTest
2
- include Driftrock::Service::Api::Website
3
-
4
- def test
5
- list_apps
6
- end
7
-
8
- end