wix-hive-ruby 0.9.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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rubocop.yml +487 -0
  4. data/.yardopts +6 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +11 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +641 -0
  9. data/Rakefile +33 -0
  10. data/e2e/activities_api_spec.rb +334 -0
  11. data/e2e/contacts_api_spec.rb +364 -0
  12. data/e2e/e2e_helper.rb +35 -0
  13. data/e2e/insights_api_spec.rb +29 -0
  14. data/lib/hive/activities/contact/contact_create_activity.rb +109 -0
  15. data/lib/hive/activities/contact/contact_form_activity.rb +31 -0
  16. data/lib/hive/activities/conversion/conversion_complete_activity.rb +33 -0
  17. data/lib/hive/activities/e_commerce/purchase_activity.rb +150 -0
  18. data/lib/hive/activities/factory.rb +71 -0
  19. data/lib/hive/activities/hotels/hotels_cancel_activity.rb +52 -0
  20. data/lib/hive/activities/hotels/hotels_confirmation_activity.rb +133 -0
  21. data/lib/hive/activities/hotels/hotels_purchase_activity.rb +48 -0
  22. data/lib/hive/activities/hotels/hotels_purchase_failed_activity.rb +59 -0
  23. data/lib/hive/activities/messaging/send_activity.rb +75 -0
  24. data/lib/hive/activities/music/album_fan_activity.rb +36 -0
  25. data/lib/hive/activities/music/album_share_activity.rb +23 -0
  26. data/lib/hive/activities/music/track_lyrics_activity.rb +38 -0
  27. data/lib/hive/activities/music/track_play_activity.rb +31 -0
  28. data/lib/hive/activities/music/track_played_activity.rb +31 -0
  29. data/lib/hive/activities/music/track_share_activity.rb +32 -0
  30. data/lib/hive/activities/music/track_skipped_activity.rb +31 -0
  31. data/lib/hive/activities/scheduler/scheduler_appointment_activity.rb +73 -0
  32. data/lib/hive/activity.rb +60 -0
  33. data/lib/hive/activity_summary.rb +24 -0
  34. data/lib/hive/connect/request/wix_api_request.rb +92 -0
  35. data/lib/hive/connect/response/error.rb +88 -0
  36. data/lib/hive/connect/response/parse_json.rb +29 -0
  37. data/lib/hive/connect/response/raise_error.rb +17 -0
  38. data/lib/hive/connect/wix_client.rb +148 -0
  39. data/lib/hive/contact.rb +153 -0
  40. data/lib/hive/cursor.rb +48 -0
  41. data/lib/hive/errors.rb +5 -0
  42. data/lib/hive/extensions/hashie_hash.rb +16 -0
  43. data/lib/hive/extensions/hashie_validate_enum.rb +11 -0
  44. data/lib/hive/rest/activities.rb +55 -0
  45. data/lib/hive/rest/api.rb +13 -0
  46. data/lib/hive/rest/contacts.rb +114 -0
  47. data/lib/hive/rest/insights.rb +17 -0
  48. data/lib/hive/util.rb +20 -0
  49. data/lib/hive/version.rb +14 -0
  50. data/lib/wix-hive-ruby.rb +5 -0
  51. data/samples/quick_start.rb +49 -0
  52. data/spec/hive/activities/contact/contact_create_activity_spec.rb +25 -0
  53. data/spec/hive/activities/contact/contact_form_activity_spec.rb +9 -0
  54. data/spec/hive/activities/conversion/conversion_complete_activity_spec.rb +9 -0
  55. data/spec/hive/activities/e_commerce/purchase_activity_spec.rb +19 -0
  56. data/spec/hive/activities/factory_spec.rb +78 -0
  57. data/spec/hive/activities/hotels/hotels_cancel_activity_spec.rb +22 -0
  58. data/spec/hive/activities/hotels/hotels_confirmation_activity_spec.rb +34 -0
  59. data/spec/hive/activities/hotels/hotels_purchase_activity_spec.rb +22 -0
  60. data/spec/hive/activities/hotels/hotels_purchase_failed_activity_spec.rb +22 -0
  61. data/spec/hive/activities/messaging/send_activity_spec.rb +13 -0
  62. data/spec/hive/activities/scheduler/scheduler_appointment_activity_spec.rb +10 -0
  63. data/spec/hive/activity_spec.rb +18 -0
  64. data/spec/hive/connect/request/wix_api_request_spec.rb +54 -0
  65. data/spec/hive/connect/response/error_spec.rb +31 -0
  66. data/spec/hive/connect/response/parse_json_spec.rb +28 -0
  67. data/spec/hive/connect/response/raise_error_spec.rb +19 -0
  68. data/spec/hive/connect/wix_client_spec.rb +103 -0
  69. data/spec/hive/contact_spec.rb +148 -0
  70. data/spec/hive/cursor_spec.rb +75 -0
  71. data/spec/hive/hashie_hash_spec.rb +23 -0
  72. data/spec/hive/rest/activities_spec.rb +87 -0
  73. data/spec/hive/rest/contacts_spec.rb +225 -0
  74. data/spec/hive/rest/insights_spec.rb +17 -0
  75. data/spec/hive/util_spec.rb +36 -0
  76. data/spec/spec_helper.rb +59 -0
  77. data/wix-hive-ruby.gemspec +38 -0
  78. metadata +392 -0
@@ -0,0 +1,35 @@
1
+ require 'wix-hive-ruby'
2
+ require 'time'
3
+ require 'vcr'
4
+
5
+ RECORD_MODE = ENV['ACCEPTANCE'] ? :all : :new_episodes
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'e2e/fixtures/vcr_cassettes'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ # Disable the use of 'should' as it is deprecated!
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect
16
+ end
17
+
18
+ config.around(:each) do |example|
19
+ VCR.use_cassette(example.metadata[:full_description], :match_requests_on => [:path], :record => RECORD_MODE) do
20
+ example.run
21
+ end
22
+ end
23
+ end
24
+
25
+ def client
26
+ Hive::Client.new do |config|
27
+ config.secret_key = 'YOUR_SECRET_KEY'
28
+ config.app_id = 'YOUR_APP_ID'
29
+ config.instance_id = 'YOUR_INSTANCE_ID'
30
+ end
31
+ end
32
+
33
+ def pendingImpl
34
+ pending 'To be implemented'
35
+ end
@@ -0,0 +1,29 @@
1
+ require_relative './e2e_helper'
2
+
3
+ describe 'Insights API' do
4
+ it '.activities_summary' do
5
+ expect(client.activities_summary).to be_a Hive::ActivitySummary
6
+ end
7
+
8
+ it '.contact_activities_summary' do
9
+ contact = Hive::Contact.new
10
+ contact.name.first = 'Wix'
11
+ contact.name.last = 'Cool'
12
+ contact.add_email(email: 'alext@wix.com', tag: 'work')
13
+ contact.add_phone(phone: '123456789', tag: 'work')
14
+
15
+ create_contact = client.new_contact(contact)
16
+
17
+ expect(create_contact).to include :contactId
18
+
19
+ activity = Hive::Activity.new(
20
+ type: FACTORY::MUSIC_ALBUM_FAN.type,
21
+ locationUrl: 'http://www.wix.com',
22
+ details: { summary: 'test', additionalInfoUrl: 'http://www.wix.com' },
23
+ info: { album: { name: 'Wix', id: '1234' } })
24
+
25
+ client.add_contact_activity(create_contact[:contactId], activity)
26
+
27
+ expect(client.contact_activities_summary(create_contact[:contactId])).to be_a Hive::ActivitySummary
28
+ end
29
+ end
@@ -0,0 +1,109 @@
1
+ # THIS IS A GENERATED FILE, DO NOT EDIT THIS
2
+ # Generated on 2014-09-10T14:02:21.470Z
3
+
4
+ require 'hashie'
5
+ require 'hive/extensions/hashie_validate_enum'
6
+
7
+ module Hive
8
+ module Activities
9
+ module Contact
10
+ class Name < Hashie::Trash
11
+ include Hashie::Extensions::IgnoreUndeclared
12
+
13
+ property :prefix
14
+ property :first
15
+ property :middle
16
+ property :last
17
+ property :suffix
18
+ end
19
+
20
+ class Company < Hashie::Trash
21
+ include Hashie::Extensions::IgnoreUndeclared
22
+
23
+ property :name
24
+ property :role
25
+ end
26
+
27
+ class Email < Hashie::Trash
28
+ include Hashie::Extensions::IgnoreUndeclared
29
+
30
+ property :tag, required: true
31
+ property :email, required: true
32
+ end
33
+
34
+ class Phone < Hashie::Trash
35
+ include Hashie::Extensions::IgnoreUndeclared
36
+
37
+ property :tag, required: true
38
+ property :phone, required: true
39
+ end
40
+
41
+ class Address < Hashie::Trash
42
+ include Hashie::Extensions::IgnoreUndeclared
43
+
44
+ property :tag, required: true
45
+ property :address
46
+ property :city
47
+ property :region
48
+ property :postalCode
49
+ property :country
50
+ end
51
+
52
+ class Date < Hashie::Trash
53
+ include Hashie::Extensions::IgnoreUndeclared
54
+
55
+ property :tag, required: true
56
+ property :date, required: true
57
+ end
58
+
59
+ class Url < Hashie::Trash
60
+ include Hashie::Extensions::IgnoreUndeclared
61
+
62
+ property :tag, required: true
63
+ property :url, required: true
64
+ end
65
+
66
+ class CreateActivity < Hashie::Trash
67
+ include Hashie::Extensions::IgnoreUndeclared
68
+ include Hashie::Extensions::Coercion
69
+
70
+ coerce_key :name, Name
71
+ coerce_key :company, Company
72
+ coerce_key :emails, Array[Email]
73
+ coerce_key :phones, Array[Phone]
74
+ coerce_key :addresses, Array[Address]
75
+ coerce_key :dates, Array[Date]
76
+ coerce_key :urls, Array[Url]
77
+
78
+ property :name
79
+ property :picture
80
+ property :company
81
+ property :emails, default: [], required: true
82
+ property :phones, default: [], required: true
83
+ property :addresses, default: [], required: true
84
+ property :dates, default: [], required: true
85
+ property :urls, default: [], required: true
86
+
87
+ def add_email(args)
88
+ emails << Email.new(args)
89
+ end
90
+
91
+ def add_phone(args)
92
+ phones << Phone.new(args)
93
+ end
94
+
95
+ def add_address(args)
96
+ addresses << Address.new(args)
97
+ end
98
+
99
+ def add_date(args)
100
+ dates << Date.new(args)
101
+ end
102
+
103
+ def add_url(args)
104
+ urls << Url.new(args)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,31 @@
1
+ # THIS IS A GENERATED FILE, DO NOT EDIT THIS
2
+ # Generated on 2014-09-10T14:02:21.439Z
3
+
4
+ require 'hashie'
5
+ require 'hive/extensions/hashie_validate_enum'
6
+
7
+ module Hive
8
+ module Activities
9
+ module Contact
10
+ class Field < Hashie::Trash
11
+ include Hashie::Extensions::IgnoreUndeclared
12
+
13
+ property :name, required: true
14
+ property :value, required: true
15
+ end
16
+
17
+ class FormActivity < Hashie::Trash
18
+ include Hashie::Extensions::IgnoreUndeclared
19
+ include Hashie::Extensions::Coercion
20
+
21
+ coerce_key :fields, Array[Field]
22
+
23
+ property :fields, default: [], required: true
24
+
25
+ def add_field(args)
26
+ fields << Field.new(args)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # THIS IS A GENERATED FILE, DO NOT EDIT THIS
2
+ # Generated on 2014-09-10T14:02:21.479Z
3
+
4
+ require 'hashie'
5
+ require 'hive/extensions/hashie_validate_enum'
6
+
7
+ module Hive
8
+ module Activities
9
+ module Conversion
10
+ class Metadata < Hashie::Trash
11
+ include Hashie::Extensions::IgnoreUndeclared
12
+
13
+ property :property, required: true
14
+ property :value, required: true
15
+ end
16
+
17
+ class CompleteActivity < Hashie::Trash
18
+ include Hashie::Extensions::IgnoreUndeclared
19
+ include Hashie::Extensions::Coercion
20
+
21
+ coerce_key :metadata, Array[Metadata]
22
+
23
+ property :conversionType, required: true, transform_with: Hashie::Validate.enum(%w(PAGEVIEW PURCHASE UPGRADE LIKE FAN NONE))
24
+ property :messageId
25
+ property :metadata, default: []
26
+
27
+ def add_metadata(args)
28
+ metadata << Metadata.new(args)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,150 @@
1
+ # THIS IS A GENERATED FILE, DO NOT EDIT THIS
2
+ # Generated on 2014-09-10T14:02:21.514Z
3
+
4
+ require 'hashie'
5
+ require 'hive/extensions/hashie_validate_enum'
6
+
7
+ module Hive
8
+ module Activities
9
+ module ECommerce
10
+ class Media < Hashie::Trash
11
+ include Hashie::Extensions::IgnoreUndeclared
12
+
13
+ property :thumbnail
14
+ end
15
+
16
+ class Variant < Hashie::Trash
17
+ include Hashie::Extensions::IgnoreUndeclared
18
+
19
+ property :title, required: true
20
+ property :value
21
+ end
22
+
23
+ class Item < Hashie::Trash
24
+ include Hashie::Extensions::IgnoreUndeclared
25
+ include Hashie::Extensions::Coercion
26
+
27
+ coerce_key :media, Media
28
+ coerce_key :variants, Array[Variant]
29
+
30
+ property :id, required: true
31
+ property :sku
32
+ property :title, required: true
33
+ property :quantity, required: true
34
+ property :price
35
+ property :formattedPrice
36
+ property :currency, required: true
37
+ property :productLink
38
+ property :weight
39
+ property :formattedWeight
40
+ property :media
41
+ property :variants, default: [], required: true
42
+
43
+ def add_variant(args)
44
+ variants << Variant.new(args)
45
+ end
46
+ end
47
+
48
+ class Coupon < Hashie::Trash
49
+ include Hashie::Extensions::IgnoreUndeclared
50
+
51
+ property :total, required: true
52
+ property :formattedTotal
53
+ property :title, required: true
54
+ end
55
+
56
+ class Tax < Hashie::Trash
57
+ include Hashie::Extensions::IgnoreUndeclared
58
+
59
+ property :total, required: true
60
+ property :formattedTotal
61
+ end
62
+
63
+ class Shipping < Hashie::Trash
64
+ include Hashie::Extensions::IgnoreUndeclared
65
+
66
+ property :total, required: true
67
+ property :formattedTotal
68
+ end
69
+
70
+ class Payment < Hashie::Trash
71
+ include Hashie::Extensions::IgnoreUndeclared
72
+ include Hashie::Extensions::Coercion
73
+
74
+ coerce_key :coupon, Coupon
75
+ coerce_key :tax, Tax
76
+ coerce_key :shipping, Shipping
77
+
78
+ property :total, required: true
79
+ property :subtotal, required: true
80
+ property :formattedTotal
81
+ property :formattedSubtotal
82
+ property :currency, required: true
83
+ property :coupon
84
+ property :tax
85
+ property :shipping
86
+ end
87
+
88
+ class ShippingAddres < Hashie::Trash
89
+ include Hashie::Extensions::IgnoreUndeclared
90
+
91
+ property :firstName
92
+ property :lastName
93
+ property :email
94
+ property :phone
95
+ property :country
96
+ property :countryCode
97
+ property :region
98
+ property :regionCode
99
+ property :city
100
+ property :address1
101
+ property :address2
102
+ property :zip
103
+ property :company
104
+ end
105
+
106
+ class BillingAddres < Hashie::Trash
107
+ include Hashie::Extensions::IgnoreUndeclared
108
+
109
+ property :firstName
110
+ property :lastName
111
+ property :email
112
+ property :phone
113
+ property :country
114
+ property :countryCode
115
+ property :region
116
+ property :regionCode
117
+ property :city
118
+ property :address1
119
+ property :address2
120
+ property :zip
121
+ property :company
122
+ end
123
+
124
+ class PurchaseActivity < Hashie::Trash
125
+ include Hashie::Extensions::IgnoreUndeclared
126
+ include Hashie::Extensions::Coercion
127
+
128
+ coerce_key :items, Array[Item]
129
+ coerce_key :payment, Payment
130
+ coerce_key :shippingAddress, ShippingAddres
131
+ coerce_key :billingAddress, BillingAddres
132
+
133
+ property :cartId, required: true
134
+ property :storeId, required: true
135
+ property :orderId
136
+ property :items, default: [], required: true
137
+ property :payment, required: true
138
+ property :shippingAddress
139
+ property :billingAddress
140
+ property :paymentGateway
141
+ property :note
142
+ property :buyerAcceptsMarketing
143
+
144
+ def add_item(args)
145
+ items << Item.new(args)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,71 @@
1
+ # THIS IS A GENERATED FILE, DO NOT EDIT THIS
2
+ # Generated on 2014-09-10T14:02:21.632Z
3
+
4
+ require 'hive/activities/contact/contact_form_activity'
5
+ require 'hive/activities/contact/contact_create_activity'
6
+ require 'hive/activities/conversion/conversion_complete_activity'
7
+ require 'hive/activities/e_commerce/purchase_activity'
8
+ require 'hive/activities/messaging/send_activity'
9
+ require 'hive/activities/music/album_fan_activity'
10
+ require 'hive/activities/music/album_share_activity'
11
+ require 'hive/activities/music/track_lyrics_activity'
12
+ require 'hive/activities/music/track_play_activity'
13
+ require 'hive/activities/music/track_played_activity'
14
+ require 'hive/activities/music/track_skipped_activity'
15
+ require 'hive/activities/music/track_share_activity'
16
+ require 'hive/activities/hotels/hotels_confirmation_activity'
17
+ require 'hive/activities/hotels/hotels_cancel_activity'
18
+ require 'hive/activities/hotels/hotels_purchase_activity'
19
+ require 'hive/activities/hotels/hotels_purchase_failed_activity'
20
+ require 'hive/activities/scheduler/scheduler_appointment_activity'
21
+
22
+ module Hive
23
+ module Activities
24
+ ActivityType = Struct.new(:klass, :type) do
25
+ end
26
+
27
+ CONTACT_CONTACT_FORM = ActivityType.new(Contact::FormActivity, 'contact/contact-form')
28
+
29
+ CONTACTS_CREATE = ActivityType.new(Contact::CreateActivity, 'contacts/create')
30
+
31
+ CONVERSION_COMPLETE = ActivityType.new(Conversion::CompleteActivity, 'conversion/complete')
32
+
33
+ E_COMMERCE_PURCHASE = ActivityType.new(ECommerce::PurchaseActivity, 'e_commerce/purchase')
34
+
35
+ MESSAGING_SEND = ActivityType.new(Messaging::SendActivity, 'messaging/send')
36
+
37
+ MUSIC_ALBUM_FAN = ActivityType.new(Music::FanActivity, 'music/album-fan')
38
+
39
+ MUSIC_ALBUM_SHARE = ActivityType.new(Music::ShareActivity, 'music/album-share')
40
+
41
+ MUSIC_TRACK_LYRICS = ActivityType.new(Music::LyricsActivity, 'music/track-lyrics')
42
+
43
+ MUSIC_TRACK_PLAY = ActivityType.new(Music::TrackPlayActivity, 'music/track-play')
44
+
45
+ MUSIC_TRACK_PLAYED = ActivityType.new(Music::TrackPlayedActivity, 'music/track-played')
46
+
47
+ MUSIC_TRACK_SKIP = ActivityType.new(Music::TrackSkippedActivity, 'music/track-skip')
48
+
49
+ MUSIC_TRACK_SHARE = ActivityType.new(Music::TrackShareActivity, 'music/track-share')
50
+
51
+ HOTELS_CONFIRMATION = ActivityType.new(Hotels::ConfirmationActivity, 'hotels/confirmation')
52
+
53
+ HOTELS_CANCEL = ActivityType.new(Hotels::CancelActivity, 'hotels/cancel')
54
+
55
+ HOTELS_PURCHASE = ActivityType.new(Hotels::PurchaseActivity, 'hotels/purchase')
56
+
57
+ HOTELS_PURCHASE_FAILED = ActivityType.new(Hotels::PurchaseFailedActivity, 'hotels/purchase-failed')
58
+
59
+ SCHEDULER_APPOINTMENT = ActivityType.new(Scheduler::AppointmentActivity, 'scheduler/appointment')
60
+
61
+ TYPES = [CONTACT_CONTACT_FORM, CONTACTS_CREATE, CONVERSION_COMPLETE, E_COMMERCE_PURCHASE, MESSAGING_SEND, MUSIC_ALBUM_FAN, MUSIC_ALBUM_SHARE, MUSIC_TRACK_LYRICS, MUSIC_TRACK_PLAY, MUSIC_TRACK_PLAYED, MUSIC_TRACK_SKIP, MUSIC_TRACK_SHARE, HOTELS_CONFIRMATION, HOTELS_CANCEL, HOTELS_PURCHASE, HOTELS_PURCHASE_FAILED, SCHEDULER_APPOINTMENT]
62
+
63
+ module_function
64
+
65
+ def class_for_type(type)
66
+ result = TYPES.find { |i| i.type == type }
67
+
68
+ result.klass unless result.nil?
69
+ end
70
+ end
71
+ end