moxiworks_platform 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 475dc2ec6d0129c5c8b8bf0ac055deaf0322d5e1
4
- data.tar.gz: 2e45e81432029a487bce5ca73145df7b16b54113
3
+ metadata.gz: af96fed391f3936ebed6ede94c6f4b05d8ddf9d5
4
+ data.tar.gz: 1a4a034af70aad0fdbbe149a7d959d7ce0ed4150
5
5
  SHA512:
6
- metadata.gz: 9ddb57edd8cd6f0c68f3f38aef503b118ce2470167f94f6f1930875db8c769f21e959a6f2a25bb9532d18ea756a9ed06a766eec3a8deefe5f902ba610461364f
7
- data.tar.gz: 16a8f1f862e5c7632bdf9f632d5695cdfdf601fb44fab0339bfb4263ad91c37813f3e8c9a51d99ae29aed3329fd90907fffc7ebb3e3687ba72d9c1af23b3ee4c
6
+ metadata.gz: 5e37c415d0b7071b1a6fdd9913f6f79e33de27cd9e6659cc8e76b02f46785c7833c0332966048083cd4ca64d8154826468d39fc3f1326b898ac6e0908a152b01
7
+ data.tar.gz: 7b02fec0cc6fea7e4ae335748f9e9b22abfa27a96059f6b7b0b3d7b27c99eec6cc492c2ee3ebddf4bfffd690be8eb4e3c0774b38b2ec59433bd60f31d87dc8a4
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in moxiworks_platform.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'vcr', '~> 2.9.3'
8
+ gem 'webmock'
9
+
10
+ end
@@ -24,7 +24,7 @@ module MoxiworksPlatform
24
24
  # Moxi Works Platform ID for the Contact
25
25
  #
26
26
  # @return [String] Moxi Works Platform ID for the contact
27
- attr_accessor :partner_contact_id
27
+ attr_accessor :moxi_works_contact_id
28
28
 
29
29
 
30
30
  # @!attribute business_website
@@ -534,7 +534,19 @@ module MoxiworksPlatform
534
534
  # success = MoxiWorksPlatform::Contact.delete(moxi_works_agent_id: '123abcd', partner_contact_id: 'myUniqueContactId' )
535
535
  #
536
536
  def self.delete(opts={})
537
- self.send_request(:delete, opts)
537
+ url = "#{MoxiworksPlatform::Config.url}/api/contacts/#{opts[:partner_contact_id]}"
538
+ required_opts = [:moxi_works_agent_id, :partner_contact_id]
539
+ required_opts.each do |opt|
540
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
541
+ opts[opt].nil? or opts[opt].empty?
542
+ end
543
+ RestClient::Request.execute(method: :delete,
544
+ url: url,
545
+ payload: opts, headers: self.headers) do |response|
546
+ puts response if MoxiworksPlatform::Config.debug
547
+ json = JSON.parse(response)
548
+ json['status'] == 'success'
549
+ end
538
550
  end
539
551
 
540
552
  # Send our remote request to the Moxi Works Platform
@@ -614,7 +626,9 @@ module MoxiworksPlatform
614
626
  url: url,
615
627
  payload: opts, headers: self.headers) do |response|
616
628
  puts response if MoxiworksPlatform::Config.debug
629
+ self.check_for_error_in_response(response)
617
630
  json = JSON.parse(response)
631
+ return false if not json['status'].nil? and json['status'] =='fail'
618
632
  contact = MoxiworksPlatform::Contact.new(json) unless json.nil? or json.empty?
619
633
  end
620
634
  contact
@@ -642,8 +656,8 @@ module MoxiworksPlatform
642
656
  # @example
643
657
  # contact = MoxiWorksPlatform::Contact.find(moxi_works_agent_id: '123abcd', partner_contact_id: 'myUniqueContactId' )
644
658
  # success = contact.delete
645
- def delete(opts={})
646
- MoxiworksPlatform::Contact.delete(opts)
659
+ def delete
660
+ MoxiworksPlatform::Contact.delete(self.to_hash)
647
661
  end
648
662
 
649
663
  private
@@ -665,7 +679,9 @@ module MoxiworksPlatform
665
679
 
666
680
  def numeric_value_for(attr_name, opts={})
667
681
  val = self.instance_variable_get("@#{attr_name}")
682
+ return val.to_i if val.is_a? Numeric and opts[:type] == :integer
668
683
  return val if val.is_a? Numeric
684
+ val.gsub!(/[^[:digit:]|\.]/, '') if val.is_a? String
669
685
  case opts[:type]
670
686
  when :integer
671
687
  instance_variable_set("@#{attr_name}", (val.nil? or val.empty?) ? nil : val.to_i)
@@ -101,7 +101,7 @@ module MoxiworksPlatform
101
101
  # Removing the secret access key from the default inspect string.
102
102
  # @api private
103
103
  def inspect
104
- "#<#{self.class.name} access_key_id=#{platform_identifier.inspect}>"
104
+ "#<#{self.class.name} platform_identifier=#{platform_identifier.inspect}>"
105
105
  end
106
106
 
107
107
  end
@@ -6,5 +6,8 @@ module MoxiworksPlatform
6
6
  # an expected argument is not defined, or the argument is in an unexpected form
7
7
  class ArgumentError < PlatformError; end
8
8
 
9
+ class AuthorizationError < PlatformError; end
10
+
11
+ class RemoteRequestFailure < PlatformError; end
9
12
  end
10
13
  end
@@ -30,7 +30,7 @@ module MoxiworksPlatform
30
30
  {
31
31
  Authorization: auth_header,
32
32
  Accept: accept_header,
33
- 'Content-Type' => content_type
33
+ 'Content-Type' => content_type_header
34
34
  }
35
35
  end
36
36
 
@@ -38,7 +38,8 @@ module MoxiworksPlatform
38
38
  #
39
39
  # @return [String] Authorization header content
40
40
  def self.auth_header
41
- raise 'MoxiworksPlatform::Credentials must be set before using' unless
41
+ raise MoxiworksPlatform::Exception::AuthorizationError,
42
+ 'MoxiworksPlatform::Credentials must be set before using' unless
42
43
  MoxiworksPlatform::Credentials.set?
43
44
  identifier = MoxiworksPlatform::Credentials.platform_identifier
44
45
  secret = MoxiworksPlatform::Credentials.platform_secret
@@ -55,10 +56,23 @@ module MoxiworksPlatform
55
56
  # formatted Content-Type header
56
57
  #
57
58
  # @return [String] Content-Type header content
58
- def self.content_type
59
+ def self.content_type_header
59
60
  'application/x-www-form-urlencoded'
60
61
  end
61
62
 
63
+ def self.check_for_error_in_response(response)
64
+ begin
65
+ json = JSON.parse(response)
66
+ rescue => e
67
+ raise MoxiworksPlatform::Exception::RemoteRequestFailure, "unable to parse remote response #{e}\n response:\n #{response}"
68
+ end
69
+ message = "unable to perform remote action on Moxi Works platform\n"
70
+ message << json['messages'].join(',') unless json['messages'].nil?
71
+
72
+ raise MoxiworksPlatform::Exception::RemoteRequestFailure, message if
73
+ not json['status'].nil? and (%w(error fail).include?(json['status']))
74
+ end
75
+
62
76
  # maps Hash values to Instance variables for mapping JSON object values to our Class attributes
63
77
  #
64
78
  def initialize(hash={})
@@ -83,7 +97,6 @@ module MoxiworksPlatform
83
97
  hash
84
98
  end
85
99
 
86
-
87
100
  end
88
101
 
89
102
  end
@@ -1,3 +1,3 @@
1
1
  module MoxiworksPlatform
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["tres.wong-godfrey@moxiworks.com"]
11
11
 
12
12
  spec.summary = %q{Ruby Moxi Works Platform Client}
13
- spec.homepage = 'http://github.io/moxiworks-platform/moxiworks-platform-ruby'
13
+ spec.homepage = 'https://github.io/moxiworks-platform/moxiworks-ruby'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
16
  spec.bindir = "exe"
@@ -21,6 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
  spec.add_development_dependency 'rest-client'
24
- spec.add_dependency 'hashie'
25
24
 
26
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxiworks_platform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tres Wong-Godfrey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: hashie
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  description:
84
70
  email:
85
71
  - tres.wong-godfrey@moxiworks.com
@@ -103,7 +89,7 @@ files:
103
89
  - lib/moxiworks_platform/resource.rb
104
90
  - lib/moxiworks_platform/version.rb
105
91
  - moxiworks_platform.gemspec
106
- homepage: http://github.io/moxiworks-platform/moxiworks-platform-ruby
92
+ homepage: https://github.io/moxiworks-platform/moxiworks-ruby
107
93
  licenses: []
108
94
  metadata: {}
109
95
  post_install_message: