driftrock-service 0.4.14 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,7 +41,7 @@ module Driftrock::Service::DriftrockModel
41
41
  object_hash = get_from_api_method.call("/#{type}/#{args.first}")
42
42
  new(object_hash)
43
43
  else
44
- super
44
+ super(method_sym, *args)
45
45
  end
46
46
  end
47
47
 
@@ -88,7 +88,6 @@ module Driftrock::Service::DriftrockModel
88
88
  else
89
89
  symbolise_keys(object_hash)
90
90
  end
91
-
92
91
  object_hash.each do |(key, value)|
93
92
  instance_variable_set(("@"+key.to_s).to_sym, value)
94
93
  instance_var_reader = lambda { instance_variable_get("@" + key.to_s) }
@@ -4,20 +4,22 @@ module Driftrock::Service::DriftrockModel
4
4
  set_api_path "/dashboard_api/company"
5
5
 
6
6
  attr_reader :id, :name
7
-
7
+
8
+ def initialize(object_hash)
9
+ super(object_hash)
10
+ if @data_sources
11
+ @channels = @data_sources.map do |channel_data|
12
+ build_channel_from_data(channel_data)
13
+ end
14
+ end
15
+ end
16
+
8
17
  def channels(refresh=false)
9
18
  unless @channels && !refresh
10
19
  @channels = []
11
20
  response = get_from_api_method.call('/channels')
12
21
  response.each do |channel_data|
13
- channel_data = symbolise_keys(channel_data)
14
- channel = Channel.new({
15
- profile_id: channel_data[:profile],
16
- })
17
- channel.channel_type = ChannelType.new({
18
- name: channel_data[:type]
19
- })
20
- @channels << channel
22
+ @channels << build_channel_from_data(channel_data)
21
23
  end
22
24
  end
23
25
  @channels
@@ -59,12 +61,28 @@ module Driftrock::Service::DriftrockModel
59
61
  !found
60
62
  end
61
63
 
62
- def add_user(user)
64
+ def invite_user(email)
63
65
  response = post_to_api_method.call(
64
- '/add_user', {user_to_add_id: user.id}
66
+ '/invite_user', {user_to_invite_email: email}
65
67
  )
66
- response['status'] == 'success'
68
+ invitation = symbolise_keys(response)
69
+ if invitation[:has_user].is_a?(String)
70
+ invitation[:has_user] = !!(invitation[:has_user] =~ /true/i)
71
+ end
72
+ invitation
67
73
  end
74
+ private
68
75
 
76
+ def build_channel_from_data(channel_data)
77
+ channel_data = symbolise_keys(channel_data)
78
+ channel = Channel.new({
79
+ profile_id: channel_data[:profile],
80
+ })
81
+ channel.channel_type = ChannelType.new({
82
+ name: channel_data[:type]
83
+ })
84
+ channel
85
+ end
86
+
69
87
  end
70
88
  end
@@ -0,0 +1,11 @@
1
+ module Driftrock::Service::DriftrockModel
2
+ class CompanyInvite
3
+ include Driftrock::Service::DriftrockModel
4
+ set_api_path "/dashboard_api/invite"
5
+ attr_reader :invite_code, :email, :has_user, :company
6
+ def initialize(object_hash)
7
+ super(object_hash)
8
+ @company = Company.new(company)
9
+ end
10
+ end
11
+ end
@@ -6,12 +6,14 @@ module Driftrock::Service::DriftrockModel
6
6
 
7
7
  [:twitter, :facebook, :adwords, :conversion, :user].each do |data_type|
8
8
  define_method("requires_#{data_type}_data?".to_sym) do
9
- requirement = method("requirement_for_#{data_type}_data").call
9
+ req_method_sym = "requirement_for_#{data_type}_data".to_sym
10
+ requirement = respond_to?(req_method_sym) ? send(req_method_sym) : :none
10
11
  requirement = requirement ? requirement.to_sym : :none
11
12
  requirement == :requires
12
13
  end
13
14
  define_method("uses_#{data_type}_data?".to_sym) do
14
- requirement = method("requirement_for_#{data_type}_data").call
15
+ req_method_sym = "requirement_for_#{data_type}_data".to_sym
16
+ requirement = respond_to?(req_method_sym) ? send(req_method_sym) : :none
15
17
  requirement = requirement ? requirement.to_sym : :none
16
18
  [:requires, :optional].include?(requirement)
17
19
  end
@@ -2,7 +2,15 @@ module Driftrock::Service::DriftrockModel
2
2
  class User
3
3
  include Driftrock::Service::DriftrockModel
4
4
  set_api_path "/dashboard_api/user"
5
- attr_reader :id, :session_id, :first_name, :last_name, :email
5
+ attr_reader :id, :session_id, :first_name, :last_name, :email, :invites
6
+
7
+ def initialize(object_hash)
8
+ super(object_hash)
9
+ @invites = [] unless invites && invites.is_a?(Array)
10
+ @invites = invites.map do |invite|
11
+ CompanyInvite.new(invite)
12
+ end
13
+ end
6
14
 
7
15
  def admin?
8
16
  @check_admin
@@ -13,22 +21,29 @@ module Driftrock::Service::DriftrockModel
13
21
  #Get session id
14
22
  end
15
23
 
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
24
  def self.find_by_session_id(session_id)
22
25
  object_hash = get_from_api_method.call("/#{session_id}")
23
26
  new(object_hash)
24
27
  end
25
28
 
26
-
27
29
  def user_admin?
28
30
  response = get_from_api_method.call("/#{session_id}/is_admin")
29
31
  response['is_admin'] =~ /true/
30
32
  end
33
+
34
+ def add_invite(invite_code)
35
+ post_to_api_method.call("/invitation/#{invite_code}/add")
36
+ end
37
+
38
+
39
+ def accept_invitation(company_id)
40
+ post_to_api_method.call("/invitation/#{company_id}/accept")
41
+ end
31
42
 
43
+ def reject_invitation(company_id)
44
+ post_to_api_method.call("/invitation/#{company_id}/reject")
45
+ end
46
+
32
47
  def add_company(company_data)
33
48
  post_to_api_method.call("/company", company_data.merge({
34
49
  user_id: session_id
@@ -1,5 +1,5 @@
1
1
  module Driftrock
2
2
  module Service
3
- VERSION = "0.4.14"
3
+ VERSION = "0.4.15"
4
4
  end
5
5
  end
@@ -26,8 +26,8 @@ describe DriftrockModel::Company do
26
26
 
27
27
  it "should allow a user to be added to a company" do
28
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
29
+ with("/invite_user", {:user_to_invite_email=>@test_user.email}).and_return({'status' => 'success'})
30
+ @test_company.invite_user(@test_user.email).should be_true
31
31
  end
32
32
 
33
33
  it "should be have knowledge of which channels it has access to" do
@@ -8,7 +8,7 @@ describe DriftrockModel::DriftrockApp do
8
8
  end
9
9
 
10
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").
11
+ @get_method.should_receive(:call).with("/app_id/string-app-id").
12
12
  and_return({id: 1, name: "test-app"})
13
13
  DriftrockModel::DriftrockApp.find_by_app_id("string-app-id").id.should == 1
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: driftrock-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14
4
+ version: 0.4.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,6 +75,7 @@ files:
75
75
  - lib/driftrock-service/driftrock_model/channel.rb
76
76
  - lib/driftrock-service/driftrock_model/channel_type.rb
77
77
  - lib/driftrock-service/driftrock_model/company.rb
78
+ - lib/driftrock-service/driftrock_model/company_invite.rb
78
79
  - lib/driftrock-service/driftrock_model/driftrock_app.rb
79
80
  - lib/driftrock-service/driftrock_model/user.rb
80
81
  - lib/driftrock-service/driftrock_model/visitor/driftrock_app.rb