amiando 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/amiando.rb CHANGED
@@ -9,6 +9,7 @@ module Amiando
9
9
  autoload :Boolean, 'amiando/boolean'
10
10
  autoload :Result, 'amiando/result'
11
11
  autoload :Autorun, 'amiando/autorun'
12
+ autoload :Utils, 'amiando/utils'
12
13
 
13
14
  autoload :ApiKey, 'amiando/api_key'
14
15
  autoload :User, 'amiando/user'
data/lib/amiando/event.rb CHANGED
@@ -3,17 +3,8 @@ module Amiando
3
3
  ##
4
4
  # http://developers.amiando.com/index.php/REST_API_Events
5
5
  class Event < Resource
6
- map :host_id, :hostId
7
6
  map :selected_date, :selectedDate, :type => :time
8
7
  map :selected_end_date, :selectedEndDate, :type => :time
9
- map :short_description, :shortDescription
10
- map :event_type, :eventType
11
- map :organisator_display_name, :organisatorDisplayName
12
- map :partner_event_url, :partnerEventUrl
13
- map :publish_search_engines, :publishSearchEngines
14
- map :search_engine_tags, :searchEngineTags
15
- map :location_description, :locationDescription
16
- map :zip_code, :zipCode
17
8
  map :creation_time, :creationTime, :type => :time
18
9
  map :last_modified, :lastModified, :type => :time
19
10
 
@@ -3,13 +3,6 @@ module Amiando
3
3
  ##
4
4
  # http://developers.amiando.com/index.php/REST_API_Partner
5
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
6
  ##
14
7
  # Creates a partner.
15
8
  #
@@ -14,11 +14,11 @@ module Amiando
14
14
  end
15
15
 
16
16
  def typecasting
17
- @@typecasting ||= {}
17
+ @typecasting ||= {}
18
18
  end
19
19
 
20
20
  def mapping
21
- @@mapping ||= {}
21
+ @mapping ||= {}
22
22
  end
23
23
 
24
24
  ##
@@ -26,7 +26,7 @@ module Amiando
26
26
  # to { :firstName => '1', :lastName => '2' }
27
27
  def map_params(attributes)
28
28
  mapped_attributes = attributes.map do |key,value|
29
- mapped_key = mapping[key] || key
29
+ mapped_key = mapping[key] || Utils.camelize(key, :lower).to_sym
30
30
  value = typecast(key, value)
31
31
  [mapped_key, value]
32
32
  end
@@ -37,7 +37,7 @@ module Amiando
37
37
  inverted_mapping = mapping.invert
38
38
  mapped_attributes = attributes.map do |key,value|
39
39
  key = key.to_sym
40
- mapped_key = inverted_mapping[key] || key
40
+ mapped_key = inverted_mapping[key] || Utils.underscore(key).to_sym
41
41
  value = inverse_typecast(mapped_key, value)
42
42
  [mapped_key, value]
43
43
  end
@@ -5,15 +5,6 @@ module Amiando
5
5
  class TicketCategory < Resource
6
6
  map :sale_start, :saleStart, :type => :time
7
7
  map :sale_end, :saleEnd, :type => :time
8
- map :reserved_count, :reservedCount
9
- map :min_sell, :minSell
10
- map :max_sell, :maxSell
11
- map :default_value, :defaultValue
12
- map :min_sell_required, :minSellRequired
13
- map :ticket_description, :ticketDescription
14
- map :display_price, :displayPrice
15
- map :display_quantity, :displayQuantity
16
- map :price_editable, :priceEditable
17
8
 
18
9
  ##
19
10
  # Creates a ticket category for an event
@@ -10,23 +10,6 @@ module Amiando
10
10
  # If you delete the related event, the ticketshop will also be deleted.
11
11
  #
12
12
  class TicketShop < Resource
13
-
14
- map :ticket_base_fee, :ticketBaseFee
15
- map :product_disagio, :productDisagio
16
- map :fee_inclusive, :feeInclusive
17
- map :shipment_fee_inclusive, :shipmentFeeInclusive
18
- map :sales_tax, :salesTax
19
- map :available_limit, :availableLimit
20
- map :show_available_tickets, :showAvailableTickets
21
- map :cancelation_possible, :cancelationPossible
22
- map :num_tickets_sold, :numTicketsSold
23
- map :total_income, :totalIncome
24
- map :total_fees, :totalFees
25
- map :collect_user_data, :collectUserData
26
- map :max_possible_number_of_participants, :maxPossibleNumberOfParticipants
27
- map :num_tickets_checked, :numTicketsChecked
28
- map :vat_id, :vatId
29
-
30
13
  ##
31
14
  # Get the ticket shop of an event.
32
15
  #
data/lib/amiando/user.rb CHANGED
@@ -3,9 +3,6 @@ module Amiando
3
3
  ##
4
4
  # http://developers.amiando.com/index.php/REST_API_Users
5
5
  class User < Resource
6
- map :first_name, :firstName
7
- map :last_name, :lastName
8
-
9
6
  ##
10
7
  # Will return a {Boolean} deferred object containing the result
11
8
  #
@@ -0,0 +1,21 @@
1
+ module Amiando
2
+ module Utils
3
+ extend self
4
+
5
+ def camelize(lower_case_and_underscored_word, first_letter_in_downcase = false)
6
+ if first_letter_in_downcase
7
+ lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
8
+ else
9
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
10
+ end
11
+ end
12
+
13
+ def underscore(camel_cased_word)
14
+ word = camel_cased_word.to_s.dup
15
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
16
+ word.tr!("-", "_")
17
+ word.downcase!
18
+ word
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Amiando
2
- VERSION = "0.3.10"
2
+ VERSION = "0.3.11"
3
3
  end
@@ -2,9 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe Amiando::Resource do
4
4
  class Wadus < Amiando::Resource
5
- map :first_name, :firstName
6
- map :last_name , :lastName
7
- map :creation, :creation, :type => :time
5
+ map :creation, :creationTime, :type => :time
8
6
 
9
7
  def self.create(params = {})
10
8
  object = new
@@ -82,7 +80,7 @@ describe Amiando::Resource do
82
80
 
83
81
  it 'maps attributes with typecasting' do
84
82
  time = Time.at(0).utc
85
- expected = { :creation => '1970-01-01T00:00:00Z' }
83
+ expected = { :creationTime => '1970-01-01T00:00:00Z' }
86
84
  Wadus.map_params(:creation => time).must_equal expected
87
85
  end
88
86
 
@@ -94,7 +92,7 @@ describe Amiando::Resource do
94
92
 
95
93
  it 'reverse maps attributes with typecasting' do
96
94
  time = Time.at(0).utc
97
- expected = { :creation_time => time }
95
+ expected = { :creation => time }
98
96
  Wadus.reverse_map_params(:creationTime => '1970-01-01T00:00:00Z').must_equal expected
99
97
  end
100
98
 
@@ -28,19 +28,25 @@ describe Amiando::TicketType do
28
28
  ticket_type.errors.must_include "com.amiando.api.rest.ticketType.TicketTypeNotAllowed"
29
29
  end
30
30
 
31
- it 'should accept a Hash as a param' do
32
- ticket_type = Amiando::TicketType.create(event.id, :type => :eticket)
33
- ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
34
- end
35
-
36
- it 'should accept a ticket string as a param' do
37
- ticket_type = Amiando::TicketType.create(event.id, :type => "TICKETTYPE_ETICKET")
38
- ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
39
- end
40
-
41
- it 'should accept a short string as a param' do
42
- ticket_type = Amiando::TicketType.create(event.id, "ETICKET")
43
- ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
31
+ describe 'param convertion' do
32
+ after do
33
+ Amiando.reset_requests
34
+ end
35
+
36
+ it 'should accept a Hash as a param' do
37
+ ticket_type = Amiando::TicketType.create(event.id, :type => :eticket)
38
+ ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
39
+ end
40
+
41
+ it 'should accept a ticket string as a param' do
42
+ ticket_type = Amiando::TicketType.create(event.id, :type => "TICKETTYPE_ETICKET")
43
+ ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
44
+ end
45
+
46
+ it 'should accept a short string as a param' do
47
+ ticket_type = Amiando::TicketType.create(event.id, "ETICKET")
48
+ ticket_type.request.params.must_equal(:type => "TICKETTYPE_ETICKET")
49
+ end
44
50
  end
45
51
  end
46
52
 
data/test/test_helper.rb CHANGED
@@ -32,6 +32,10 @@ module Amiando
32
32
  self.api_key = TEST_KEY = Amiando::Factory.create(:api_key, :name => 'test key').key
33
33
 
34
34
  TEST_USER = Amiando::Factory.create(:user, :username => "jorgellop-base-#{HydraCache.revision}@example.com")
35
+
36
+ def self.reset_requests
37
+ @requests = []
38
+ end
35
39
  end
36
40
 
37
41
  HydraCache.prefix = nil
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 10
10
- version: 0.3.10
9
+ - 11
10
+ version: 0.3.11
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: 2012-01-30 00:00:00 Z
19
+ date: 2012-01-31 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: typhoeus
@@ -125,6 +125,7 @@ files:
125
125
  - lib/amiando/ticket_shop.rb
126
126
  - lib/amiando/ticket_type.rb
127
127
  - lib/amiando/user.rb
128
+ - lib/amiando/utils.rb
128
129
  - lib/amiando/version.rb
129
130
  - test/amiando/amiando_test.rb
130
131
  - test/amiando/api_key_test.rb