amiando 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  /.rvmrc
6
6
  /TAGS
7
+ /.yardoc/*
data/README.md CHANGED
@@ -5,6 +5,17 @@ documentation here:
5
5
 
6
6
  http://developers.amiando.com/index.php/REST_API
7
7
 
8
+ ## Installation
9
+
10
+ Simply install with:
11
+
12
+ gem install amiando
13
+
14
+ To parse the json results we use the [multi_json](https://rubygems.org/gems/multi_json)
15
+ gem. We suggest that you add at least one fast json parsing library, like
16
+ [json](https://rubygems.org/gems/json) or [yajl-ruby](https://rubygems.org/gems/yajl-ruby).
17
+ Otherwise it will use `multi_json`'s bundled json parser.
18
+
8
19
  ## Basic usage
9
20
 
10
21
  The gem has been implemented with the idea that requests can be done in
@@ -23,7 +34,7 @@ You can also do synchronous requests by prepending 'sync_' to the method name:
23
34
 
24
35
  albert = Amiando::User.sync_find(1234)
25
36
 
26
- ### Note
37
+ ### Notation
27
38
 
28
39
  All attributes should be used in snake_case format instead of the CamelCase
29
40
  used in the official documentation. For example, for a user, you should call
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency 'typhoeus'
22
- s.add_dependency 'json'
22
+ s.add_dependency 'multi_json'
23
23
 
24
24
  s.add_development_dependency 'minitest'
25
25
  s.add_development_dependency 'webmock'
@@ -1,6 +1,6 @@
1
1
  require "amiando/version"
2
2
  require "typhoeus"
3
- require "json"
3
+ require "multi_json"
4
4
 
5
5
  module Amiando
6
6
  autoload :Request, 'amiando/request'
@@ -36,14 +36,17 @@ module Amiando
36
36
  URL = 'https://amiando.com'
37
37
  TEST_URL = 'https://test.amiando.com'
38
38
 
39
+ # Connect to the production server
39
40
  def production!
40
41
  @production = true
41
42
  end
42
43
 
44
+ # Connect to the test server (default)
43
45
  def development!
44
46
  @production = false
45
47
  end
46
48
 
49
+ # @return [String] the url for the environment
47
50
  def base_url
48
51
  @production ? URL : TEST_URL
49
52
  end
@@ -52,6 +55,7 @@ module Amiando
52
55
  @requests ||= []
53
56
  end
54
57
 
58
+ # Runs all queued requests
55
59
  def run
56
60
  requests.each{ |request| hydra.queue(request) }
57
61
  hydra.run
@@ -63,6 +67,12 @@ module Amiando
63
67
  @hydra ||= Typhoeus::Hydra.new
64
68
  end
65
69
 
70
+ ##
71
+ # Allows to switch temporarily the API key
72
+ #
73
+ # @param [String] api API key
74
+ # @param [Block] block block to execute with the given key
75
+ # @return the result of the block
66
76
  def with_key(key)
67
77
  old_key = Amiando.api_key
68
78
  Amiando.api_key = key
@@ -70,5 +80,6 @@ module Amiando
70
80
  ensure
71
81
  Amiando.api_key = old_key
72
82
  end
83
+
73
84
  end
74
85
  end
@@ -7,7 +7,10 @@ module Amiando
7
7
  ##
8
8
  # Creates an {ApiKey}.
9
9
  #
10
- # @param [Hash] possible attributes that can be set on creation.
10
+ # @param [Hash] attributes possible attributes that can be set on creation.
11
+ #
12
+ # @raise [ArgumentError] if no name provided in attributes
13
+ # @return [ApiKey]
11
14
  def self.create(attributes)
12
15
  raise ArgumentError.new('ApiKey name field is mandatory') unless attributes[:name]
13
16
 
@@ -20,7 +23,8 @@ module Amiando
20
23
  ##
21
24
  # Updates an {ApiKey}.
22
25
  #
23
- # @param [Hash] possible attributes that can be updated.
26
+ # @param [Hash] attributes possible attributes that can be updated.
27
+ # @return [Boolean] the result value
24
28
  def self.update(id, attributes)
25
29
  object = Boolean.new(:success)
26
30
  post object, "/api/apiKey/#{id}", :params => attributes
@@ -28,6 +32,8 @@ module Amiando
28
32
  object
29
33
  end
30
34
 
35
+ protected
36
+
31
37
  def populate(response_body)
32
38
  extract_attributes_from(response_body, 'apiKey')
33
39
  end
@@ -20,6 +20,8 @@ module Amiando
20
20
  ##
21
21
  # Creates an event.
22
22
  #
23
+ # @param [Hash] attributes
24
+ #
23
25
  # @return [Event] will not return the full event and only the id attribute
24
26
  # will be available.
25
27
  def self.create(attributes)
@@ -34,6 +36,9 @@ module Amiando
34
36
  ##
35
37
  # Updates an event.
36
38
  #
39
+ # @param id
40
+ # @param [Hash] attributes
41
+ #
37
42
  # @return [Boolean] if it was successful or not.
38
43
  def self.update(id, attributes)
39
44
  object = Result.new
@@ -44,6 +49,10 @@ module Amiando
44
49
 
45
50
  ##
46
51
  # Fetch an event
52
+ #
53
+ # @param id
54
+ #
55
+ # @return [Event]
47
56
  def self.find(id)
48
57
  object = new
49
58
  get object, "/api/event/#{id}"
@@ -53,6 +62,10 @@ module Amiando
53
62
 
54
63
  ##
55
64
  # See if an event id exists
65
+ #
66
+ # @param identifier
67
+ #
68
+ # @return [Boolean] if it exists or not
56
69
  def self.exists?(identifier)
57
70
  object = Boolean.new('exists')
58
71
  get object, "api/event/exists", :params => { :identifier => identifier }
@@ -63,7 +76,7 @@ module Amiando
63
76
  ##
64
77
  # Deletes an event
65
78
  #
66
- # @param [Integer] event id
79
+ # @param [Integer] id event id
67
80
  #
68
81
  # @return [Boolean] with the result of the operation
69
82
  def self.delete(id)
@@ -76,7 +89,7 @@ module Amiando
76
89
  ##
77
90
  # Activate an event
78
91
  #
79
- # @param [Integer] the event id
92
+ # @param [Integer] id event id
80
93
  #
81
94
  # @return [Result] if it was activated or not.
82
95
  def self.activate(id)
@@ -91,6 +104,7 @@ module Amiando
91
104
  #
92
105
  # @param [Hash] a hash with 1 entry, either :identifier or :title
93
106
  #
107
+ # @raise [ArgumentError] if no identifier or title supplied, or if both present
94
108
  # @return [Result] with an array of ids
95
109
  def self.search(by)
96
110
  unless by[:identifier].nil? ^ by[:title].nil? # XOR
@@ -104,7 +118,9 @@ module Amiando
104
118
  end
105
119
 
106
120
  ##
107
- # @param user id
121
+ # Find all events from a user
122
+ #
123
+ # @param user_id
108
124
  #
109
125
  # @return [Result] with a list of the event ids by this user
110
126
  def self.find_all_by_user_id(user_id)
@@ -115,7 +131,7 @@ module Amiando
115
131
  object
116
132
  end
117
133
 
118
- private
134
+ protected
119
135
 
120
136
  def populate(response_body)
121
137
  extract_attributes_from(response_body, 'event')
@@ -28,7 +28,7 @@ module Amiando
28
28
  ##
29
29
  # Updates the partner.
30
30
  #
31
- # @param the internal id of the partner to update.
31
+ # @param id the internal id of the partner to update.
32
32
  # @param [Hash] attributes
33
33
  #
34
34
  # @return [Result] saying if the update was successful
@@ -40,7 +40,9 @@ module Amiando
40
40
  end
41
41
 
42
42
  ##
43
- # @param id of the partner
43
+ # Find a partner
44
+ #
45
+ # @param id id of the partner
44
46
  #
45
47
  # @return [Partner] the partner with that id
46
48
  def self.find(id)
@@ -57,5 +59,3 @@ module Amiando
57
59
  end
58
60
  end
59
61
  end
60
-
61
-
@@ -4,8 +4,8 @@ module Amiando
4
4
  ##
5
5
  # Create a payment type for an event
6
6
  #
7
- # @param event id
8
- # @param string or symbol of the following:
7
+ # @param event_id
8
+ # @param type string or symbol of the following:
9
9
  # * PAYMENT_TYPE_ELV
10
10
  # * PAYMENT_TYPE_CC
11
11
  # * PAYMENT_TYPE_INVOICE
@@ -33,7 +33,9 @@ module Amiando
33
33
  end
34
34
 
35
35
  ##
36
- # @param event id
36
+ # Find all Payment Types of an event
37
+ #
38
+ # @param event_id
37
39
  #
38
40
  # @return [Result] with the list of payment types for that event.
39
41
  def self.find_all_by_event_id(event_id)
@@ -54,7 +56,9 @@ module Amiando
54
56
  end
55
57
 
56
58
  ##
57
- # @param payment type id
59
+ # Find a Payment Type
60
+ #
61
+ # @param payment_type_id
58
62
  #
59
63
  # @return [PaymentType] the payment type with that id
60
64
  def self.find(payment_type_id)
@@ -73,7 +73,7 @@ module Amiando
73
73
  raise Error::ServiceDown.new(response.body)
74
74
  end
75
75
 
76
- parsed_body = JSON.parse(response.body)
76
+ parsed_body = MultiJson.decode(response.body)
77
77
 
78
78
  if parsed_body['errors'] && parsed_body['errors'].include?('com.amiando.api.rest.MissingParam.apikey')
79
79
  raise Error::MissingApiKey.new('This call requires an apikey')
@@ -21,6 +21,8 @@ module Amiando
21
21
  #
22
22
  # @param event_id
23
23
  # @param [Hash] attributes
24
+ #
25
+ # @return [TicketCategory] only id or errors are set
24
26
  def self.create(event_id, attributes)
25
27
  object = new
26
28
  post object, "api/event/#{event_id}/ticketCategory/create",
@@ -33,7 +35,10 @@ module Amiando
33
35
  ##
34
36
  # Update a ticket_category
35
37
  #
38
+ # @param ticket_category_id
36
39
  # @param [Hash] attributes
40
+ #
41
+ # @return [Result] if it was succesful or not with possible errors
37
42
  def self.update(ticket_category_id, attributes)
38
43
  object = Result.new
39
44
  post object, "api/ticketCategory/#{ticket_category_id}", :params => attributes
@@ -44,7 +49,7 @@ module Amiando
44
49
  ##
45
50
  # Find a ticket category.
46
51
  #
47
- # @param ticket category id
52
+ # @param ticket_category_id
48
53
  #
49
54
  # @return [TicketCategory]
50
55
  def self.find(ticket_category_id)
@@ -55,7 +60,7 @@ module Amiando
55
60
  end
56
61
 
57
62
  ##
58
- # @param event id
63
+ # @param event_id
59
64
  # @param [Symbol]
60
65
  # :ids if you only want to fetch the ids.
61
66
  # :full if you want the whole objects
@@ -82,7 +87,7 @@ module Amiando
82
87
  object
83
88
  end
84
89
 
85
- private
90
+ protected
86
91
 
87
92
  def populate(response_body)
88
93
  extract_attributes_from(response_body, 'ticketCategory')
@@ -43,7 +43,8 @@ module Amiando
43
43
  ##
44
44
  # Updates the ticket shop.
45
45
  #
46
- # @param [String] username
46
+ # @param event_id
47
+ # @param [Hash] attributes
47
48
  #
48
49
  # @return [Boolean] deferred object indicating the result of the update.
49
50
  def self.update(event_id, attributes)
@@ -53,8 +54,7 @@ module Amiando
53
54
  object
54
55
  end
55
56
 
56
-
57
- private
57
+ protected
58
58
 
59
59
  def populate(response_body)
60
60
  extract_attributes_from(response_body, 'ticketShop')
@@ -1,3 +1,3 @@
1
1
  module Amiando
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiando
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jorge Dias
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-26 00:00:00 +02:00
19
+ date: 2011-10-28 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: json
37
+ name: multi_json
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false