amiando 0.2.1 → 0.3.0

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.
data/README.md CHANGED
@@ -34,8 +34,8 @@ first_name instead of firstName.
34
34
  The full amiando API isn't fully implemented yet, however you can find here the
35
35
  ones currently available.
36
36
 
37
- * [ApiKey](http://rdoc.info/github/xing/amiando/master/Amiando/ApiKeyt)
38
- * Partner
37
+ * [ApiKey](http://rdoc.info/github/xing/amiando/master/Amiando/ApiKey)
38
+ * [Partner](http://rdoc.info/github/xing/amiando/master/Amiando/Partner)
39
39
  * [User](http://rdoc.info/github/xing/amiando/master/Amiando/User) (some methods
40
40
  still missing)
41
41
  * [Event](http://rdoc.info/github/xing/amiando/master/Amiando/Event)
@@ -7,13 +7,15 @@ module Amiando
7
7
  autoload :Resource, 'amiando/resource'
8
8
  autoload :Boolean, 'amiando/boolean'
9
9
  autoload :Result, 'amiando/result'
10
+ autoload :Autorun, 'amiando/autorun'
11
+
10
12
  autoload :ApiKey, 'amiando/api_key'
11
13
  autoload :User, 'amiando/user'
14
+ autoload :Partner, 'amiando/partner'
12
15
  autoload :Event, 'amiando/event'
13
16
  autoload :TicketCategory, 'amiando/ticket_category'
14
17
  autoload :TicketShop, 'amiando/ticket_shop'
15
18
  autoload :PaymentType, 'amiando/payment_type'
16
- autoload :Autorun, 'amiando/autorun'
17
19
 
18
20
  module Error
19
21
  class ServiceDown < Exception; end
@@ -11,8 +11,8 @@ module Amiando
11
11
  def self.create(attributes)
12
12
  raise ArgumentError.new('ApiKey name field is mandatory') unless attributes[:name]
13
13
 
14
- object = new
15
- request = post object, '/api/apiKey/create', :params => attributes
14
+ object = new
15
+ post object, '/api/apiKey/create', :params => attributes
16
16
 
17
17
  object
18
18
  end
@@ -22,8 +22,8 @@ module Amiando
22
22
  #
23
23
  # @param [Hash] possible attributes that can be updated.
24
24
  def self.update(id, attributes)
25
- object = Boolean.new(:success)
26
- request = post object, "/api/apiKey/#{id}", :params => attributes
25
+ object = Boolean.new(:success)
26
+ post object, "/api/apiKey/#{id}", :params => attributes
27
27
 
28
28
  object
29
29
  end
@@ -23,8 +23,8 @@ module Amiando
23
23
  # @return [Event] will not return the full event and only the id attribute
24
24
  # will be available.
25
25
  def self.create(attributes)
26
- object = new
27
- request = post object, '/api/event/create',
26
+ object = new
27
+ post object, '/api/event/create',
28
28
  :params => map_params(attributes),
29
29
  :populate_method => :populate_create
30
30
 
@@ -36,13 +36,8 @@ module Amiando
36
36
  #
37
37
  # @return [Boolean] if it was successful or not.
38
38
  def self.update(id, attributes)
39
- object = Result.new do |response_body, result|
40
- unless response_body['success']
41
- result.errors = response_body['errors']
42
- end
43
- response_body['success']
44
- end
45
- request = post object, "/api/event/#{id}", :params => map_params(attributes)
39
+ object = Result.new
40
+ post object, "/api/event/#{id}", :params => map_params(attributes)
46
41
 
47
42
  object
48
43
  end
@@ -50,8 +45,8 @@ module Amiando
50
45
  ##
51
46
  # Fetch an event
52
47
  def self.find(id)
53
- object = new
54
- request = get object, "/api/event/#{id}"
48
+ object = new
49
+ get object, "/api/event/#{id}"
55
50
 
56
51
  object
57
52
  end
@@ -59,9 +54,8 @@ module Amiando
59
54
  ##
60
55
  # See if an event id exists
61
56
  def self.exists?(identifier)
62
- object = Boolean.new('exists')
63
- request = get object, "api/event/exists",
64
- :params => { :identifier => identifier }
57
+ object = Boolean.new('exists')
58
+ get object, "api/event/exists", :params => { :identifier => identifier }
65
59
 
66
60
  object
67
61
  end
@@ -74,7 +68,7 @@ module Amiando
74
68
  # @return [Boolean] with the result of the operation
75
69
  def self.delete(id)
76
70
  object = Boolean.new('deleted')
77
- request = do_request object, :delete, "/api/event/#{id}"
71
+ do_request object, :delete, "/api/event/#{id}"
78
72
 
79
73
  object
80
74
  end
@@ -86,13 +80,8 @@ module Amiando
86
80
  #
87
81
  # @return [Result] if it was activated or not.
88
82
  def self.activate(id)
89
- object = Result.new do |response_body, result|
90
- unless response_body['success']
91
- result.errors = response_body['errors']
92
- end
93
- response_body['success']
94
- end
95
- request = post object, "/api/event/#{id}/activate"
83
+ object = Result.new
84
+ post object, "/api/event/#{id}/activate"
96
85
 
97
86
  object
98
87
  end
@@ -108,17 +97,21 @@ module Amiando
108
97
  raise ArgumentError.new('Events can be searched either by identifier or by title, include only one.')
109
98
  end
110
99
 
111
- object = Result.new { |response_body| response_body['ids'] }
112
- request = get object, '/api/event/find', :params => by
100
+ object = Result.new { |response_body| response_body['ids'] }
101
+ get object, '/api/event/find', :params => by
113
102
 
114
103
  object
115
104
  end
116
105
 
106
+ ##
107
+ # @param user id
108
+ #
109
+ # @return [Result] with a list of the event ids by this user
117
110
  def self.find_all_by_user_id(user_id)
118
111
  object = Result.new do |response_body|
119
112
  response_body['events']
120
113
  end
121
- request = get object, "/api/user/#{user_id}/events"
114
+ get object, "/api/user/#{user_id}/events"
122
115
  object
123
116
  end
124
117
 
@@ -0,0 +1,61 @@
1
+ module Amiando
2
+
3
+ ##
4
+ # http://developers.amiando.com/index.php/REST_API_Partner
5
+ class Partner < Resource
6
+ map :admin_id, :adminId
7
+ map :default_country, :defaultCountry
8
+ map :menu_css_url, :menuCssUrl
9
+ map :ticket_shop_css_url, :ticketShopCssUrl
10
+ map :sso_callback, :ssoCallback
11
+ map :referrer_partner_id, :referrerPartnerId
12
+
13
+ ##
14
+ # Creates a partner.
15
+ #
16
+ # @param [Hash] attributes
17
+ #
18
+ # @return [Partner] but will only have the id loaded
19
+ def self.create(attributes)
20
+ object = new
21
+ post object, '/api/partner/create',
22
+ :params => map_params(attributes),
23
+ :populate_method => :populate_create
24
+
25
+ object
26
+ end
27
+
28
+ ##
29
+ # Updates the partner.
30
+ #
31
+ # @param the internal id of the partner to update.
32
+ # @param [Hash] attributes
33
+ #
34
+ # @return [Result] saying if the update was successful
35
+ def self.update(id, attributes)
36
+ object = Result.new
37
+ post object, "/api/partner/#{id}", :params => map_params(attributes)
38
+
39
+ object
40
+ end
41
+
42
+ ##
43
+ # @param id of the partner
44
+ #
45
+ # @return [Partner] the partner with that id
46
+ def self.find(id)
47
+ object = new
48
+ get object, "/api/partner/#{id}"
49
+
50
+ object
51
+ end
52
+
53
+ private
54
+
55
+ def populate(response_body)
56
+ extract_attributes_from(response_body, 'partner')
57
+ end
58
+ end
59
+ end
60
+
61
+
@@ -1,23 +1,21 @@
1
1
  module Amiando
2
2
  class PaymentType < Resource
3
3
 
4
- # /event/{id}/paymentTypes <-- all paymentTypes of the event
5
- # /event/{id}/paymentType/create <-- creating a new paymentType
6
- # /paymentType/{id} <-- returns the paymentType (used for udpates etc)
7
-
8
- # PaymentType has just the following three variables:
9
-
10
- # Id
11
- # Type (String of the following: {PAYMENT_TYPE_ELV, PAYMENT_TYPE_CC, PAYMENT_TYPE_INVOICE, PAYMENT_TYPE_PREPAYMENT, PAYMENT_TYPE_PP, PAYMENT_TYPE_ONLOCATION}) [CC = CreditCard, PP = PayPal]
12
- # Active (boolean)
13
4
  ##
14
5
  # Create a payment type for an event
15
6
  #
16
7
  # @param event id
17
- # @param [Type] Type (String of the following:
18
- # PAYMENT_TYPE_ELV, PAYMENT_TYPE_CC, PAYMENT_TYPE_INVOICE, PAYMENT_TYPE_PREPAYMENT,
19
- # PAYMENT_TYPE_PP, PAYMENT_TYPE_ONLOCATION) [CC = CreditCard, PP = PayPal]
20
- # It will also accept :cc, :invoice, etc and convert them appropiately
8
+ # @param string or symbol of the following:
9
+ # * PAYMENT_TYPE_ELV
10
+ # * PAYMENT_TYPE_CC
11
+ # * PAYMENT_TYPE_INVOICE
12
+ # * PAYMENT_TYPE_PREPAYMENT
13
+ # * PAYMENT_TYPE_PP
14
+ # * PAYMENT_TYPE_ONLOCATION
15
+ #
16
+ # [CC = CreditCard, PP = PayPal]
17
+ #
18
+ # It will also accept :cc, :invoice, etc and convert them appropriately
21
19
  #
22
20
  def self.create(event_id, type)
23
21
  unless type =~ /payment_type_\w+/i
@@ -25,12 +23,8 @@ module Amiando
25
23
  end
26
24
 
27
25
  object = Result.new do |response_body, result|
28
- if response_body['success']
29
- response_body['id']
30
- else
31
- result.errors = response_body['errors']
32
- false
33
- end
26
+ result.errors = response_body['errors']
27
+ response_body['id'] || false
34
28
  end
35
29
 
36
30
  post object, "api/event/#{event_id}/paymentType/create", :params => { :type => type.upcase }
@@ -38,6 +32,10 @@ module Amiando
38
32
  object
39
33
  end
40
34
 
35
+ ##
36
+ # @param event id
37
+ #
38
+ # @return [Result] with the list of payment types for that event.
41
39
  def self.find_all_by_event_id(event_id)
42
40
  object = Result.new do |response_body, result|
43
41
  if response_body['success']
@@ -55,6 +53,10 @@ module Amiando
55
53
  object
56
54
  end
57
55
 
56
+ ##
57
+ # @param payment type id
58
+ #
59
+ # @return [PaymentType] the payment type with that id
58
60
  def self.find(payment_type_id)
59
61
  object = new
60
62
 
@@ -10,12 +10,16 @@ module Amiando
10
10
  class Result
11
11
  include Amiando::Autorun
12
12
 
13
- attr_accessor :request, :response, :errors
13
+ attr_accessor :request, :response, :errors, :success
14
14
 
15
- autorun :request, :response, :result, :errors
15
+ autorun :request, :response, :result, :errors, :success
16
16
 
17
17
  def initialize(&block)
18
18
  @populator = block
19
+ @populator ||= Proc.new do |response_body, result|
20
+ result.errors = response_body['errors']
21
+ response_body['success']
22
+ end
19
23
  end
20
24
 
21
25
  def populate(response_body)
@@ -24,6 +28,7 @@ module Amiando
24
28
  elsif @populator.arity == 2
25
29
  @result = @populator.call(response_body, self)
26
30
  end
31
+ @success = response_body['success']
27
32
  end
28
33
  end
29
34
  end
@@ -35,15 +35,7 @@ module Amiando
35
35
  #
36
36
  # @param [Hash] attributes
37
37
  def self.update(ticket_category_id, attributes)
38
- object = Result.new do |response_body, result|
39
- if response_body['success']
40
- true
41
- else
42
- result.errors = response_body['errors']
43
- false
44
- end
45
- end
46
-
38
+ object = Result.new
47
39
  post object, "api/ticketCategory/#{ticket_category_id}", :params => attributes
48
40
 
49
41
  object
@@ -34,8 +34,8 @@ module Amiando
34
34
  #
35
35
  # @return [TicektShop] the event's ticketshop
36
36
  def self.find(event_id)
37
- object = new
38
- request = get object, "api/event/#{event_id}/ticketShop"
37
+ object = new
38
+ get object, "api/event/#{event_id}/ticketShop"
39
39
 
40
40
  object
41
41
  end
@@ -47,8 +47,8 @@ module Amiando
47
47
  #
48
48
  # @return [Boolean] deferred object indicating the result of the update.
49
49
  def self.update(event_id, attributes)
50
- object = Boolean.new('success')
51
- request = post object, "/api/event/#{event_id}/ticketShop", :params => map_params(attributes)
50
+ object = Boolean.new('success')
51
+ post object, "/api/event/#{event_id}/ticketShop", :params => map_params(attributes)
52
52
 
53
53
  object
54
54
  end
@@ -12,7 +12,7 @@ module Amiando
12
12
  # @param [String] username
13
13
  def self.exists?(username)
14
14
  object = Boolean.new('exists')
15
- request = get object, "api/user/exists",
15
+ get object, "api/user/exists",
16
16
  :params => { :username => username }
17
17
 
18
18
  object
@@ -28,7 +28,7 @@ module Amiando
28
28
  response_body['ids'].first
29
29
  end
30
30
 
31
- request = get object, "api/user/find",
31
+ get object, "api/user/find",
32
32
  :params => { :username => username }
33
33
 
34
34
  object
@@ -41,7 +41,7 @@ module Amiando
41
41
  # @param [Hash] attributes
42
42
  def self.create(attributes)
43
43
  object = new
44
- request = post object, '/api/user/create',
44
+ post object, '/api/user/create',
45
45
  :params => map_params(attributes),
46
46
  :populate_method => :populate_create
47
47
 
@@ -56,7 +56,7 @@ module Amiando
56
56
  # @param [String] username
57
57
  def self.update(user_id, attributes)
58
58
  object = Boolean.new('success')
59
- request = post object, "/api/user/#{user_id}", :params => map_params(attributes)
59
+ post object, "/api/user/#{user_id}", :params => map_params(attributes)
60
60
 
61
61
  object
62
62
  end
@@ -68,7 +68,7 @@ module Amiando
68
68
  # @param user_id
69
69
  def self.find(user_id)
70
70
  object = new
71
- request = get object, "api/user/#{user_id}"
71
+ get object, "api/user/#{user_id}"
72
72
 
73
73
  object
74
74
  end
@@ -80,7 +80,7 @@ module Amiando
80
80
  # @param user_id
81
81
  def self.delete(user_id)
82
82
  object = Boolean.new('deleted')
83
- request = do_request object, :delete, "/api/user/#{user_id}"
83
+ do_request object, :delete, "/api/user/#{user_id}"
84
84
 
85
85
  object
86
86
  end
@@ -90,16 +90,8 @@ module Amiando
90
90
  # @param user_id
91
91
  # @param [String] password
92
92
  def self.request_permission(user_id, password)
93
- object = Result.new do |response_body, result|
94
- if response_body['success']
95
- true
96
- else
97
- result.errors = response_body['errors']
98
- false
99
- end
100
- end
101
-
102
- request = post object, "api/user/#{user_id}/requestPermission", :params => { :password => password }
93
+ object = Result.new
94
+ post object, "api/user/#{user_id}/requestPermission", :params => { :password => password }
103
95
 
104
96
  object
105
97
  end
@@ -111,7 +103,7 @@ module Amiando
111
103
  # @param user_id
112
104
  def self.logout(user_id)
113
105
  object = Boolean.new('success')
114
- request = post object, "/api/user/#{user_id}/logout"
106
+ post object, "/api/user/#{user_id}/logout"
115
107
 
116
108
  object
117
109
  end
@@ -1,3 +1,3 @@
1
1
  module Amiando
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::Partner do
4
+ before do
5
+ HydraCache.prefix = 'Partner'
6
+ end
7
+
8
+ after do
9
+ HydraCache.prefix = nil
10
+ end
11
+
12
+ describe 'create' do
13
+ it 'creates a partner successfully' do
14
+ api_key = Amiando::Factory.create(:api_key, :name => "partner-create-#{HydraCache.revision}")
15
+ Amiando.with_key api_key.key do
16
+ username = "partner_create-#{HydraCache.revision}@example.com"
17
+ user = Amiando::Factory.create(:user, :username => username)
18
+ partner = Amiando::Partner.create(
19
+ :admin_id => user.id,
20
+ :name => "Partner name",
21
+ :language => "en",
22
+ :default_country => "ES"
23
+ )
24
+ Amiando.run
25
+
26
+ partner.id.wont_be_nil
27
+ end
28
+ end
29
+
30
+ it 'handles errors' do
31
+ partner = Amiando::Partner.create(
32
+ :admin_id => nil,
33
+ :name => "Partner name",
34
+ :language => "en",
35
+ :default_country => "ES"
36
+ )
37
+ Amiando.run
38
+
39
+ partner.errors.wont_be_empty
40
+ end
41
+ end
42
+
43
+ describe 'update' do
44
+ it 'updates the object' do
45
+ api_key = Amiando::Factory.create(:api_key, :name => "partner-update-#{HydraCache.revision}")
46
+ Amiando.with_key api_key.key do
47
+ username = "partner_update-#{HydraCache.revision}@example.com"
48
+ user = Amiando::Factory.create(:user, :username => username)
49
+ partner = Amiando::Partner.create(
50
+ :admin_id => user.id,
51
+ :name => "Partner name",
52
+ :language => "en",
53
+ :default_country => "ES"
54
+ )
55
+ Amiando.run
56
+
57
+ update = Amiando::Partner.update(partner.id, :name => 'wadus')
58
+ Amiando.run
59
+
60
+ update.result.must_equal true
61
+ end
62
+ end
63
+ end
64
+
65
+ describe 'find' do
66
+ it 'finds the object' do
67
+ api_key = Amiando::Factory.create(:api_key, :name => "partner-find-#{HydraCache.revision}")
68
+ Amiando.with_key api_key.key do
69
+ username = "partner_find-#{HydraCache.revision}@example.com"
70
+ user = Amiando::Factory.create(:user, :username => username)
71
+ partner = Amiando::Partner.create(
72
+ :admin_id => user.id,
73
+ :name => "to be found",
74
+ :language => "en",
75
+ :default_country => "ES"
76
+ )
77
+ Amiando.run
78
+
79
+ found = Amiando::Partner.find(partner.id)
80
+ Amiando.run
81
+
82
+ found.must_equal partner
83
+ found.name.must_equal "to be found"
84
+ end
85
+ end
86
+ end
87
+
88
+ end