moesif_api 2.1.0 → 2.1.1
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 +4 -4
- data/lib/moesif_api/configuration.rb +5 -2
- data/lib/moesif_api/controllers/base_controller.rb +6 -1
- data/lib/moesif_api/http/faraday_client.rb +2 -2
- data/lib/moesif_api/moesif_api_client.rb +2 -1
- data/test/controllers/controller_test_base.rb +2 -2
- data/test/controllers/test_api_controller.rb +77 -0
- data/test/test_helper.rb +1 -1
- metadata +2 -3
- data/lib/moesif_api.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4df54ebc345c812cec2fcea15554f134b13106a4e8f7081330afde4aab75be21
|
4
|
+
data.tar.gz: c0d0b57c8d1d804c3f80730f140bae583173fb2755cfae68a00a0123425fa0d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 533086975aaf0c04f403e374195c6cd5489cf155e00335e6a9927788b81681f715f2bb305ee918d31a06d937fbc00726e67f601e14db98753ded8bb43fab91d1
|
7
|
+
data.tar.gz: d586ba59a922b9a3c371b68b022dc940863d778ef8de6a4112f6cdd04293955f9bf308d2e3ba7e6998c5da6ffd5e3083c0b4138561236581481cc7db836d4dc8
|
@@ -8,9 +8,11 @@ module MoesifApi
|
|
8
8
|
# Your Application Id for authentication/authorization
|
9
9
|
@application_id = 'SET_ME'
|
10
10
|
|
11
|
-
@version = '2.
|
11
|
+
@version = '2.1.1'
|
12
12
|
|
13
|
-
@user_agent = "moesifapi-ruby/2.
|
13
|
+
@user_agent = "moesifapi-ruby/2.1.1"
|
14
|
+
|
15
|
+
@retry_count = 5
|
14
16
|
|
15
17
|
# create the getters and setters
|
16
18
|
class << self
|
@@ -18,6 +20,7 @@ module MoesifApi
|
|
18
20
|
attr_accessor :application_id
|
19
21
|
attr_accessor :version
|
20
22
|
attr_accessor :user_agent
|
23
|
+
attr_accessor :retry_count
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -19,8 +19,13 @@ module MoesifApi
|
|
19
19
|
|
20
20
|
def validate_response(context)
|
21
21
|
return if context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
22
|
+
res = context.response;
|
22
23
|
|
23
|
-
|
24
|
+
if res.nil?
|
25
|
+
raise APIException.new 'No Http Response, maybe timeout', context
|
26
|
+
else
|
27
|
+
raise APIException.new 'HTTP Response Not OK ' + res.status_code.to_s + ' ' + res.raw_body.to_s, context
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
end
|
@@ -15,8 +15,9 @@ module MoesifApi
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Initializer with authentication and configuration parameters
|
18
|
-
def initialize(application_id, user_agent=nil)
|
18
|
+
def initialize(application_id, user_agent=nil, retry_count=5)
|
19
19
|
Configuration.application_id = application_id
|
20
|
+
Configuration.retry_count = retry_count
|
20
21
|
unless user_agent.nil?
|
21
22
|
Configuration.user_agent = user_agent
|
22
23
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'test/unit'
|
5
|
-
|
5
|
+
require_relative '../../lib/moesif_api.rb'
|
6
6
|
require_relative '../test_helper.rb'
|
7
7
|
require_relative '../http_response_catcher.rb'
|
8
8
|
|
@@ -15,7 +15,7 @@ class ControllerTestBase < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
# Called only once for a test class before any test has executed.
|
17
17
|
def self.startup
|
18
|
-
@@api_client = MoesifAPIClient.new("
|
18
|
+
@@api_client = MoesifAPIClient.new("Your Moesif Application Id")
|
19
19
|
@@request_timeout = 30
|
20
20
|
@@assert_precision = 0.01
|
21
21
|
end
|
@@ -85,6 +85,83 @@ class ApiControllerTests < ControllerTestBase
|
|
85
85
|
assert_equal(@response_catcher.response.status_code, 201)
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_add_bad_event()
|
89
|
+
# Parameters for the API call
|
90
|
+
|
91
|
+
req_headers = JSON.parse('{'\
|
92
|
+
'"Host": "api.acmeinc.com",'\
|
93
|
+
'"Accept": "*/*",'\
|
94
|
+
'"Connection": "Keep-Alive",'\
|
95
|
+
'"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.0.2; C6906 Build/14.5.A.0.242)",'\
|
96
|
+
'"Content-Type": "application/json",'\
|
97
|
+
'"Content-Length": "126",'\
|
98
|
+
'"Accept-Encoding": "gzip"'\
|
99
|
+
'}')
|
100
|
+
|
101
|
+
req_body = JSON.parse( '{'\
|
102
|
+
'"items": ['\
|
103
|
+
'{'\
|
104
|
+
'"type": 1,'\
|
105
|
+
'"id": "fwfrf"'\
|
106
|
+
'},'\
|
107
|
+
'{'\
|
108
|
+
'"type": 2,'\
|
109
|
+
'"id": "d43d3f"'\
|
110
|
+
'}'\
|
111
|
+
']'\
|
112
|
+
'}')
|
113
|
+
|
114
|
+
rsp_headers = JSON.parse('{'\
|
115
|
+
'"Date": "Tue, 6 Jan 2019 23:46:49 GMT",'\
|
116
|
+
'"Vary": "Accept-Encoding",'\
|
117
|
+
'"Pragma": "no-cache",'\
|
118
|
+
'"Expires": "-1",'\
|
119
|
+
'"Content-Type": "application/json; charset=utf-8",'\
|
120
|
+
'"Cache-Control": "no-cache"'\
|
121
|
+
'}')
|
122
|
+
|
123
|
+
rsp_body = JSON.parse('{'\
|
124
|
+
'"Error": "InvalidArgumentException",'\
|
125
|
+
'"Message": "Missing field field_a"'\
|
126
|
+
'}')
|
127
|
+
|
128
|
+
metadata = JSON.parse('{'\
|
129
|
+
'"foo": "rubytestmeta",'\
|
130
|
+
'"bar": "rubytestmedat2"'\
|
131
|
+
'}')
|
132
|
+
|
133
|
+
event_req = EventRequestModel.new()
|
134
|
+
event_req.time = Time.now.utc.iso8601
|
135
|
+
event_req.uri = nil
|
136
|
+
event_req.verb = "POST"
|
137
|
+
event_req.api_version = "1.1.0"
|
138
|
+
event_req.ip_address = "61.48.220.123"
|
139
|
+
event_req.headers = req_headers
|
140
|
+
event_req.body = req_body
|
141
|
+
|
142
|
+
event_rsp = EventResponseModel.new()
|
143
|
+
event_rsp.time = (Time.now.utc + 2).iso8601
|
144
|
+
event_rsp.status = 400
|
145
|
+
event_rsp.headers = rsp_headers
|
146
|
+
event_rsp.body = rsp_body
|
147
|
+
|
148
|
+
event_model = EventModel.new()
|
149
|
+
event_model.request = event_req
|
150
|
+
event_model.response = event_rsp
|
151
|
+
event_model.user_id = "my_user_id"
|
152
|
+
event_model.company_id = "my_company_id"
|
153
|
+
event_model.metadata = metadata
|
154
|
+
event_model.session_token = "random"
|
155
|
+
|
156
|
+
# Perform the API call through the SDK function
|
157
|
+
|
158
|
+
error = assert_raises(APIException) do
|
159
|
+
self.class.controller.create_event(event_model)
|
160
|
+
end
|
161
|
+
puts 'error: ' + error.message;
|
162
|
+
assert_match(/422|400/, error.message, "The error message should contain '422' or '400'")
|
163
|
+
end
|
164
|
+
|
88
165
|
# Add Batched Events via Ingestion API
|
89
166
|
def test_add_batched_events()
|
90
167
|
# Parameters for the API call
|
data/test/test_helper.rb
CHANGED
@@ -84,7 +84,7 @@ class TestHelper
|
|
84
84
|
if not @cache.keys.include? url
|
85
85
|
@cache[url] = Tempfile.new('APIMatic')
|
86
86
|
@cache[url].binmode
|
87
|
-
@cache[url].write(open(url,
|
87
|
+
@cache[url].write(File.open(url, 'rb').read)
|
88
88
|
else
|
89
89
|
@cache[url].open
|
90
90
|
@cache[url].binmode
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moesif_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moesif, Inc
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -115,7 +115,6 @@ extra_rdoc_files: []
|
|
115
115
|
files:
|
116
116
|
- LICENSE
|
117
117
|
- README.md
|
118
|
-
- lib/moesif_api.rb
|
119
118
|
- lib/moesif_api/api_helper.rb
|
120
119
|
- lib/moesif_api/configuration.rb
|
121
120
|
- lib/moesif_api/controllers/api_controller.rb
|
data/lib/moesif_api.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'openssl'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
# Exceptions
|
6
|
-
require_relative 'moesif_api/exceptions/api_exception.rb'
|
7
|
-
|
8
|
-
# Helper Files
|
9
|
-
require_relative 'moesif_api/api_helper.rb'
|
10
|
-
require_relative 'moesif_api/configuration.rb'
|
11
|
-
require_relative 'moesif_api/moesif_api_client.rb'
|
12
|
-
|
13
|
-
# Http
|
14
|
-
require_relative 'moesif_api/http/http_call_back.rb'
|
15
|
-
require_relative 'moesif_api/http/http_client.rb'
|
16
|
-
require_relative 'moesif_api/http/http_method_enum.rb'
|
17
|
-
require_relative 'moesif_api/http/http_request.rb'
|
18
|
-
require_relative 'moesif_api/http/http_response.rb'
|
19
|
-
require_relative 'moesif_api/http/http_context.rb'
|
20
|
-
require_relative 'moesif_api/http/faraday_client.rb'
|
21
|
-
|
22
|
-
# Models
|
23
|
-
require_relative 'moesif_api/models/base_model.rb'
|
24
|
-
require_relative 'moesif_api/models/event_request_model.rb'
|
25
|
-
require_relative 'moesif_api/models/event_model.rb'
|
26
|
-
require_relative 'moesif_api/models/event_response_model.rb'
|
27
|
-
require_relative 'moesif_api/models/status_model.rb'
|
28
|
-
require_relative 'moesif_api/models/user_model.rb'
|
29
|
-
require_relative 'moesif_api/models/company_model.rb'
|
30
|
-
require_relative 'moesif_api/models/campaign_model.rb'
|
31
|
-
|
32
|
-
# Controllers
|
33
|
-
require_relative 'moesif_api/controllers/base_controller.rb'
|
34
|
-
require_relative 'moesif_api/controllers/api_controller.rb'
|
35
|
-
require_relative 'moesif_api/controllers/health_controller.rb'
|