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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +487 -0
- data/.yardopts +6 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +641 -0
- data/Rakefile +33 -0
- data/e2e/activities_api_spec.rb +334 -0
- data/e2e/contacts_api_spec.rb +364 -0
- data/e2e/e2e_helper.rb +35 -0
- data/e2e/insights_api_spec.rb +29 -0
- data/lib/hive/activities/contact/contact_create_activity.rb +109 -0
- data/lib/hive/activities/contact/contact_form_activity.rb +31 -0
- data/lib/hive/activities/conversion/conversion_complete_activity.rb +33 -0
- data/lib/hive/activities/e_commerce/purchase_activity.rb +150 -0
- data/lib/hive/activities/factory.rb +71 -0
- data/lib/hive/activities/hotels/hotels_cancel_activity.rb +52 -0
- data/lib/hive/activities/hotels/hotels_confirmation_activity.rb +133 -0
- data/lib/hive/activities/hotels/hotels_purchase_activity.rb +48 -0
- data/lib/hive/activities/hotels/hotels_purchase_failed_activity.rb +59 -0
- data/lib/hive/activities/messaging/send_activity.rb +75 -0
- data/lib/hive/activities/music/album_fan_activity.rb +36 -0
- data/lib/hive/activities/music/album_share_activity.rb +23 -0
- data/lib/hive/activities/music/track_lyrics_activity.rb +38 -0
- data/lib/hive/activities/music/track_play_activity.rb +31 -0
- data/lib/hive/activities/music/track_played_activity.rb +31 -0
- data/lib/hive/activities/music/track_share_activity.rb +32 -0
- data/lib/hive/activities/music/track_skipped_activity.rb +31 -0
- data/lib/hive/activities/scheduler/scheduler_appointment_activity.rb +73 -0
- data/lib/hive/activity.rb +60 -0
- data/lib/hive/activity_summary.rb +24 -0
- data/lib/hive/connect/request/wix_api_request.rb +92 -0
- data/lib/hive/connect/response/error.rb +88 -0
- data/lib/hive/connect/response/parse_json.rb +29 -0
- data/lib/hive/connect/response/raise_error.rb +17 -0
- data/lib/hive/connect/wix_client.rb +148 -0
- data/lib/hive/contact.rb +153 -0
- data/lib/hive/cursor.rb +48 -0
- data/lib/hive/errors.rb +5 -0
- data/lib/hive/extensions/hashie_hash.rb +16 -0
- data/lib/hive/extensions/hashie_validate_enum.rb +11 -0
- data/lib/hive/rest/activities.rb +55 -0
- data/lib/hive/rest/api.rb +13 -0
- data/lib/hive/rest/contacts.rb +114 -0
- data/lib/hive/rest/insights.rb +17 -0
- data/lib/hive/util.rb +20 -0
- data/lib/hive/version.rb +14 -0
- data/lib/wix-hive-ruby.rb +5 -0
- data/samples/quick_start.rb +49 -0
- data/spec/hive/activities/contact/contact_create_activity_spec.rb +25 -0
- data/spec/hive/activities/contact/contact_form_activity_spec.rb +9 -0
- data/spec/hive/activities/conversion/conversion_complete_activity_spec.rb +9 -0
- data/spec/hive/activities/e_commerce/purchase_activity_spec.rb +19 -0
- data/spec/hive/activities/factory_spec.rb +78 -0
- data/spec/hive/activities/hotels/hotels_cancel_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_confirmation_activity_spec.rb +34 -0
- data/spec/hive/activities/hotels/hotels_purchase_activity_spec.rb +22 -0
- data/spec/hive/activities/hotels/hotels_purchase_failed_activity_spec.rb +22 -0
- data/spec/hive/activities/messaging/send_activity_spec.rb +13 -0
- data/spec/hive/activities/scheduler/scheduler_appointment_activity_spec.rb +10 -0
- data/spec/hive/activity_spec.rb +18 -0
- data/spec/hive/connect/request/wix_api_request_spec.rb +54 -0
- data/spec/hive/connect/response/error_spec.rb +31 -0
- data/spec/hive/connect/response/parse_json_spec.rb +28 -0
- data/spec/hive/connect/response/raise_error_spec.rb +19 -0
- data/spec/hive/connect/wix_client_spec.rb +103 -0
- data/spec/hive/contact_spec.rb +148 -0
- data/spec/hive/cursor_spec.rb +75 -0
- data/spec/hive/hashie_hash_spec.rb +23 -0
- data/spec/hive/rest/activities_spec.rb +87 -0
- data/spec/hive/rest/contacts_spec.rb +225 -0
- data/spec/hive/rest/insights_spec.rb +17 -0
- data/spec/hive/util_spec.rb +36 -0
- data/spec/spec_helper.rb +59 -0
- data/wix-hive-ruby.gemspec +38 -0
- metadata +392 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# THIS IS A GENERATED FILE, DO NOT EDIT THIS
|
2
|
+
# Generated on 2014-09-10T14:02:21.549Z
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'hive/extensions/hashie_validate_enum'
|
6
|
+
|
7
|
+
module Hive
|
8
|
+
module Activities
|
9
|
+
module Music
|
10
|
+
class TrackPlayActivity < Hashie::Trash
|
11
|
+
include Hashie::Extensions::IgnoreUndeclared
|
12
|
+
include Hashie::Extensions::Coercion
|
13
|
+
|
14
|
+
class Album < Hashie::Trash
|
15
|
+
include Hashie::Extensions::IgnoreUndeclared
|
16
|
+
|
17
|
+
property :name
|
18
|
+
property :id
|
19
|
+
end
|
20
|
+
|
21
|
+
coerce_key :track, Track
|
22
|
+
coerce_key :album, Album
|
23
|
+
coerce_key :artist, Artist
|
24
|
+
|
25
|
+
property :track
|
26
|
+
property :album
|
27
|
+
property :artist
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# THIS IS A GENERATED FILE, DO NOT EDIT THIS
|
2
|
+
# Generated on 2014-09-10T14:02:21.555Z
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'hive/extensions/hashie_validate_enum'
|
6
|
+
|
7
|
+
module Hive
|
8
|
+
module Activities
|
9
|
+
module Music
|
10
|
+
class TrackPlayedActivity < Hashie::Trash
|
11
|
+
include Hashie::Extensions::IgnoreUndeclared
|
12
|
+
include Hashie::Extensions::Coercion
|
13
|
+
|
14
|
+
class Album < Hashie::Trash
|
15
|
+
include Hashie::Extensions::IgnoreUndeclared
|
16
|
+
|
17
|
+
property :name
|
18
|
+
property :id
|
19
|
+
end
|
20
|
+
|
21
|
+
coerce_key :track, Track
|
22
|
+
coerce_key :album, Album
|
23
|
+
coerce_key :artist, Artist
|
24
|
+
|
25
|
+
property :track
|
26
|
+
property :album
|
27
|
+
property :artist
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# THIS IS A GENERATED FILE, DO NOT EDIT THIS
|
2
|
+
# Generated on 2014-09-10T14:02:21.569Z
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'hive/extensions/hashie_validate_enum'
|
6
|
+
|
7
|
+
module Hive
|
8
|
+
module Activities
|
9
|
+
module Music
|
10
|
+
class TrackShareActivity < Hashie::Trash
|
11
|
+
include Hashie::Extensions::IgnoreUndeclared
|
12
|
+
include Hashie::Extensions::Coercion
|
13
|
+
|
14
|
+
class Album < Hashie::Trash
|
15
|
+
include Hashie::Extensions::IgnoreUndeclared
|
16
|
+
|
17
|
+
property :name
|
18
|
+
property :id
|
19
|
+
end
|
20
|
+
|
21
|
+
coerce_key :track, Track
|
22
|
+
coerce_key :album, Album
|
23
|
+
coerce_key :artist, Artist
|
24
|
+
|
25
|
+
property :track
|
26
|
+
property :album
|
27
|
+
property :artist
|
28
|
+
property :sharedTo, required: true, transform_with: Hashie::Validate.enum(%w(FACEBOOK GOOGLE_PLUS TWITTER))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# THIS IS A GENERATED FILE, DO NOT EDIT THIS
|
2
|
+
# Generated on 2014-09-10T14:02:21.561Z
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'hive/extensions/hashie_validate_enum'
|
6
|
+
|
7
|
+
module Hive
|
8
|
+
module Activities
|
9
|
+
module Music
|
10
|
+
class TrackSkippedActivity < Hashie::Trash
|
11
|
+
include Hashie::Extensions::IgnoreUndeclared
|
12
|
+
include Hashie::Extensions::Coercion
|
13
|
+
|
14
|
+
class Album < Hashie::Trash
|
15
|
+
include Hashie::Extensions::IgnoreUndeclared
|
16
|
+
|
17
|
+
property :name
|
18
|
+
property :id
|
19
|
+
end
|
20
|
+
|
21
|
+
coerce_key :track, Track
|
22
|
+
coerce_key :album, Album
|
23
|
+
coerce_key :artist, Artist
|
24
|
+
|
25
|
+
property :track
|
26
|
+
property :album
|
27
|
+
property :artist
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# THIS IS A GENERATED FILE, DO NOT EDIT THIS
|
2
|
+
# Generated on 2014-09-10T14:02:21.629Z
|
3
|
+
|
4
|
+
require 'hashie'
|
5
|
+
require 'hive/extensions/hashie_validate_enum'
|
6
|
+
|
7
|
+
module Hive
|
8
|
+
module Activities
|
9
|
+
module Scheduler
|
10
|
+
class Location < Hashie::Trash
|
11
|
+
include Hashie::Extensions::IgnoreUndeclared
|
12
|
+
|
13
|
+
property :address
|
14
|
+
property :city
|
15
|
+
property :region
|
16
|
+
property :postalCode
|
17
|
+
property :country
|
18
|
+
property :url
|
19
|
+
end
|
20
|
+
|
21
|
+
class Time < Hashie::Trash
|
22
|
+
include Hashie::Extensions::IgnoreUndeclared
|
23
|
+
|
24
|
+
property :start, required: true
|
25
|
+
property :end, required: true
|
26
|
+
property :timezone, required: true
|
27
|
+
end
|
28
|
+
|
29
|
+
class Name < Hashie::Trash
|
30
|
+
include Hashie::Extensions::IgnoreUndeclared
|
31
|
+
|
32
|
+
property :prefix
|
33
|
+
property :first
|
34
|
+
property :middle
|
35
|
+
property :last
|
36
|
+
property :suffix
|
37
|
+
end
|
38
|
+
|
39
|
+
class Attendee < Hashie::Trash
|
40
|
+
include Hashie::Extensions::IgnoreUndeclared
|
41
|
+
include Hashie::Extensions::Coercion
|
42
|
+
|
43
|
+
coerce_key :name, Name
|
44
|
+
|
45
|
+
property :contactId
|
46
|
+
property :name
|
47
|
+
property :phone
|
48
|
+
property :email
|
49
|
+
property :notes
|
50
|
+
property :self
|
51
|
+
end
|
52
|
+
|
53
|
+
class AppointmentActivity < Hashie::Trash
|
54
|
+
include Hashie::Extensions::IgnoreUndeclared
|
55
|
+
include Hashie::Extensions::Coercion
|
56
|
+
|
57
|
+
coerce_key :location, Location
|
58
|
+
coerce_key :time, Time
|
59
|
+
coerce_key :attendees, Array[Attendee]
|
60
|
+
|
61
|
+
property :title, required: true
|
62
|
+
property :description, required: true
|
63
|
+
property :location
|
64
|
+
property :time
|
65
|
+
property :attendees, default: []
|
66
|
+
|
67
|
+
def add_attendee(args)
|
68
|
+
attendees << Attendee.new(args)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'time'
|
3
|
+
require 'hive/activities/factory'
|
4
|
+
|
5
|
+
module Hive
|
6
|
+
class ActivityResult < Hashie::Trash
|
7
|
+
include Hashie::Extensions::IgnoreUndeclared
|
8
|
+
|
9
|
+
property :activityId
|
10
|
+
property :contactId
|
11
|
+
end
|
12
|
+
|
13
|
+
class ActivityDetails < Hashie::Trash
|
14
|
+
include Hashie::Extensions::IgnoreUndeclared
|
15
|
+
|
16
|
+
property :additionalInfoUrl
|
17
|
+
property :summary
|
18
|
+
end
|
19
|
+
|
20
|
+
class Activity < Hashie::Trash
|
21
|
+
include Hashie::Extensions::IgnoreUndeclared
|
22
|
+
include Hashie::Extensions::Coercion
|
23
|
+
# include Hashie::Extensions::CompactJSON
|
24
|
+
|
25
|
+
coerce_key :activityDetails, ActivityDetails
|
26
|
+
|
27
|
+
property :id
|
28
|
+
property :createdAt, default: Time.now.iso8601(3)
|
29
|
+
|
30
|
+
property :activityType, from: :type, required: true
|
31
|
+
alias_method :type=, :activityType=
|
32
|
+
alias_method :type, :activityType
|
33
|
+
|
34
|
+
property :activityLocationUrl, from: :locationUrl
|
35
|
+
alias_method :locationUrl=, :activityLocationUrl=
|
36
|
+
alias_method :locationUrl, :activityLocationUrl
|
37
|
+
|
38
|
+
property :activityDetails, from: :details, default: ActivityDetails.new
|
39
|
+
alias_method :details=, :activityDetails=
|
40
|
+
alias_method :details, :activityDetails
|
41
|
+
|
42
|
+
property :activityInfo, from: :info, required: true
|
43
|
+
alias_method :info=, :activityInfo=
|
44
|
+
alias_method :info, :activityInfo
|
45
|
+
|
46
|
+
def initialize(hash = {})
|
47
|
+
super(hash)
|
48
|
+
transform_activity_info unless hash.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def transform_activity_info
|
54
|
+
type = Activities.class_for_type(activityType)
|
55
|
+
|
56
|
+
# rubocop:disable Style/VariableName
|
57
|
+
self.activityInfo = type.new(activityInfo) if type
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Hive
|
4
|
+
class ActivityTypeSummary < Hashie::Trash
|
5
|
+
include Hashie::Extensions::IgnoreUndeclared
|
6
|
+
|
7
|
+
property :activityType
|
8
|
+
property :total
|
9
|
+
property :from
|
10
|
+
property :until
|
11
|
+
end
|
12
|
+
|
13
|
+
class ActivitySummary < Hashie::Trash
|
14
|
+
include Hashie::Extensions::IgnoreUndeclared
|
15
|
+
include Hashie::Extensions::Coercion
|
16
|
+
|
17
|
+
coerce_key :activityTypes, Array[ActivityTypeSummary]
|
18
|
+
|
19
|
+
property :activityTypes
|
20
|
+
property :total
|
21
|
+
property :from
|
22
|
+
property :until
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
require 'hive/cursor'
|
5
|
+
|
6
|
+
module Hive
|
7
|
+
module Request
|
8
|
+
class WixAPIRequest
|
9
|
+
attr_accessor :verb, :path, :body, :params, :headers
|
10
|
+
|
11
|
+
def initialize(client, verb, path, options = {})
|
12
|
+
@client = client
|
13
|
+
@verb = verb.to_sym
|
14
|
+
@path = path
|
15
|
+
@body = options.fetch(:body, {})
|
16
|
+
@params = options.fetch(:params, {})
|
17
|
+
@headers = options.fetch(:headers, {})
|
18
|
+
end
|
19
|
+
|
20
|
+
def options
|
21
|
+
{ body: @body.clone, params: @params.clone, headers: @headers.clone }
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform
|
25
|
+
sign_request
|
26
|
+
@client.wix_request(self).body
|
27
|
+
end
|
28
|
+
|
29
|
+
def perform_with_object(klass)
|
30
|
+
klass.new(perform)
|
31
|
+
end
|
32
|
+
|
33
|
+
def perform_with_cursor(klass)
|
34
|
+
Hive::Cursor.new(perform, klass, self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize_copy(_other)
|
38
|
+
@path = @path.dup
|
39
|
+
@body = @body.dup
|
40
|
+
@params = @params.dup
|
41
|
+
@headers = @headers.dup
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def sign_request
|
47
|
+
@timestamp = Time.now.iso8601(3)
|
48
|
+
append_default_params
|
49
|
+
append_wix_headers
|
50
|
+
@headers[CaseSensitiveString.new('x-wix-signature')] = calculate_signature
|
51
|
+
end
|
52
|
+
|
53
|
+
def append_default_params
|
54
|
+
@params['version'] ||= @client.api_version
|
55
|
+
end
|
56
|
+
|
57
|
+
def append_wix_headers
|
58
|
+
@headers.update(wix_headers)
|
59
|
+
end
|
60
|
+
|
61
|
+
def wix_headers
|
62
|
+
{ CaseSensitiveString.new('x-wix-instance-id') => @client.instance_id,
|
63
|
+
CaseSensitiveString.new('x-wix-application-id') => @client.app_id,
|
64
|
+
CaseSensitiveString.new('x-wix-timestamp') => @timestamp }
|
65
|
+
end
|
66
|
+
|
67
|
+
def calculate_signature
|
68
|
+
out = "#{@verb.upcase}\n/#{@path}\n#{sorted_parameter_values.join("\n")}#{@body.empty? ? '' : "\n#{@body}"}"
|
69
|
+
sign_data(out)
|
70
|
+
end
|
71
|
+
|
72
|
+
def sorted_parameter_values
|
73
|
+
{}.update(params).update(wix_headers).sort_by { |k, _v| k.to_s }.map { |_k, v| v }
|
74
|
+
end
|
75
|
+
|
76
|
+
def sign_data(data)
|
77
|
+
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, @client.secret_key, data)
|
78
|
+
Base64.urlsafe_encode64(hmac).gsub(/\+/, '-').gsub(/\//, '_').gsub('=', '')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class CaseSensitiveString < String
|
83
|
+
def downcase
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def capitalize
|
88
|
+
self
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Hive
|
2
|
+
module Response
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :error_message, :error_code, :wix_error_code
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def from_response(response)
|
8
|
+
message, error_code, wix_error_code = parse_body(response.body)
|
9
|
+
new(message, error_code, wix_error_code)
|
10
|
+
end
|
11
|
+
|
12
|
+
# rubocop:disable Style/MethodLength
|
13
|
+
def errors
|
14
|
+
@errors ||= {
|
15
|
+
400 => Hive::Response::Error::BadRequest,
|
16
|
+
403 => Hive::Response::Error::Forbidden,
|
17
|
+
404 => Hive::Response::Error::NotFound,
|
18
|
+
408 => Hive::Response::Error::RequestTimeout,
|
19
|
+
429 => Hive::Response::Error::TooManyRequests,
|
20
|
+
500 => Hive::Response::Error::InternalServerError,
|
21
|
+
502 => Hive::Response::Error::BadGateway,
|
22
|
+
503 => Hive::Response::Error::ServiceUnavailable,
|
23
|
+
504 => Hive::Response::Error::GatewayTimeout
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def parse_body(body)
|
30
|
+
if body.nil?
|
31
|
+
['', '', '']
|
32
|
+
elsif !body.is_a?(Hash)
|
33
|
+
[body, '', '']
|
34
|
+
else
|
35
|
+
[body[:message].chomp, body[:errorCode], body[:wixErrorCode]]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(message = '', error_code = nil, wix_error_code = '')
|
41
|
+
super(message)
|
42
|
+
@error_message = message
|
43
|
+
@error_code = error_code
|
44
|
+
@wix_error_code = wix_error_code
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"#{@error_message}, errorCode: #{@error_code}, wixErrorCode: #{@wix_error_code}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Raised when the HIVE returns a 4xx HTTP status code
|
52
|
+
ClientError = Class.new(self)
|
53
|
+
|
54
|
+
BadRequest = Class.new(ClientError)
|
55
|
+
|
56
|
+
Unauthorized = Class.new(ClientError)
|
57
|
+
|
58
|
+
Forbidden = Class.new(ClientError)
|
59
|
+
|
60
|
+
AlreadyFavorited = Class.new(Forbidden)
|
61
|
+
|
62
|
+
AlreadyRetweeted = Class.new(Forbidden)
|
63
|
+
|
64
|
+
DuplicateStatus = Class.new(Forbidden)
|
65
|
+
|
66
|
+
NotFound = Class.new(ClientError)
|
67
|
+
|
68
|
+
NotAcceptable = Class.new(ClientError)
|
69
|
+
|
70
|
+
RequestTimeout = Class.new(ClientError)
|
71
|
+
|
72
|
+
UnprocessableEntity = Class.new(ClientError)
|
73
|
+
|
74
|
+
TooManyRequests = Class.new(ClientError)
|
75
|
+
|
76
|
+
# Raised when the HIVE returns a 5xx HTTP status code
|
77
|
+
ServerError = Class.new(self)
|
78
|
+
|
79
|
+
InternalServerError = Class.new(ServerError)
|
80
|
+
|
81
|
+
BadGateway = Class.new(ServerError)
|
82
|
+
|
83
|
+
ServiceUnavailable = Class.new(ServerError)
|
84
|
+
|
85
|
+
GatewayTimeout = Class.new(ServerError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|