AvrijAnalyticsUtility 0.3.0 → 0.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ea7a04a55f4cc2f53f9c19ec852e0ae84c1ad08
|
4
|
+
data.tar.gz: cfcef712320e9fe051fc13a64efc183934998263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c33c6ca019c08f04c35325e1ec1567b1e808f40cef96b55178e2c3d4b9c2032b06053780e362e704b38378b2ac461a233c0bc282acc03b21ad8cf33585f79e8
|
7
|
+
data.tar.gz: 42d7929bb5e7a7e588ac557c4a977117506e0cddca39acb602f1c02dd5b01bb3e54f78ee2107dc6eb15f3502095a19cb3ff308d754f5ac2d6e3f22606f9e95a7
|
@@ -1,79 +1,5 @@
|
|
1
1
|
require "AvrijAnalyticsUtility/version"
|
2
|
-
require "AvrijAnalyticsUtility/EyesoverConnection"
|
3
2
|
|
4
3
|
module AvrijAnalyticsUtility
|
5
4
|
|
6
|
-
# Get all social media post given from date_1 to date_2
|
7
|
-
#
|
8
|
-
# ==== Attributes
|
9
|
-
#
|
10
|
-
# * +param_username+ - Username
|
11
|
-
# * +param_password+ - Password
|
12
|
-
# * +param_auth_uri+ - Authentication end point
|
13
|
-
# * +param_data_uri+ - API data source end point
|
14
|
-
# * +param_from_datetime+ - From date value
|
15
|
-
# * +param_to_datetime+ - To date value
|
16
|
-
#
|
17
|
-
# ==== Return
|
18
|
-
#
|
19
|
-
# * returns GET request OBJECT
|
20
|
-
#
|
21
|
-
# ==== Notes
|
22
|
-
# * datetime must have the following format : 2017-06-30T00:00:00+04:00
|
23
|
-
#
|
24
|
-
# ====
|
25
|
-
def self.getAllSocialMediaPostfromDateRange(param_username,param_password,param_auth_uri,param_data_uri,param_from_datetime,param_to_datetime)
|
26
|
-
query_values = {
|
27
|
-
"entity" => "All identified",
|
28
|
-
"from" => param_from_datetime,
|
29
|
-
"to" => param_to_datetime,
|
30
|
-
"facebook" => "0",
|
31
|
-
"facebookPost" => "0",
|
32
|
-
"reddit"=>"0",
|
33
|
-
"youtube" => "0",
|
34
|
-
"youtubeComment"=>"0",
|
35
|
-
"twitter" => "0",
|
36
|
-
"news" => "0"
|
37
|
-
}
|
38
|
-
puts query_values
|
39
|
-
conn = APIConnection.new
|
40
|
-
conn.authenticate(param_username,param_password,param_auth_uri)
|
41
|
-
get_request_object = conn.getSocialMediaPost(param_data_uri,query_values)
|
42
|
-
return get_request_object
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get all entities
|
46
|
-
#
|
47
|
-
# ==== Attributes
|
48
|
-
#
|
49
|
-
# * +param_username+ - Username
|
50
|
-
# * +param_password+ - Password
|
51
|
-
# * +param_auth_uri+ - API endpoint for authentication
|
52
|
-
# * +param_data_uri+ - API endpoint for data request
|
53
|
-
#
|
54
|
-
# ==== Return
|
55
|
-
#
|
56
|
-
# * returns GET request OBJECT
|
57
|
-
#
|
58
|
-
# ====
|
59
|
-
def self.getAllEntities(param_username,param_password,param_auth_uri,param_data_uri)
|
60
|
-
conn = APIConnection.new
|
61
|
-
conn.authenticate(param_username,param_password,param_auth_uri)
|
62
|
-
get_request_object = conn.getAllEntities(param_data_uri)
|
63
|
-
return get_request_object
|
64
|
-
end
|
65
|
-
|
66
|
-
# Writes json string to json file
|
67
|
-
#
|
68
|
-
# ==== Attributes
|
69
|
-
#
|
70
|
-
# * +param_jsonstring+ - json string value
|
71
|
-
# * +param_outputfile+ - json file name
|
72
|
-
#
|
73
|
-
# ====
|
74
|
-
def self.jsonString_to_json(param_jsonstring,param_outputfile)
|
75
|
-
File.open(param_outputfile,"w") do |f|
|
76
|
-
f.write(param_jsonstring.to_json)
|
77
|
-
end
|
78
|
-
end
|
79
5
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module AvrijAnalyticsUtility
|
6
|
+
class APIConnector
|
7
|
+
|
8
|
+
#Constructor
|
9
|
+
def initialize(base_uri,username,password)
|
10
|
+
@base_uri = base_uri
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@auth_token = nil
|
14
|
+
@auth_value = nil
|
15
|
+
@header_hash = nil
|
16
|
+
@query_hash = nil
|
17
|
+
@body_hash = nil
|
18
|
+
@request_options = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# Perform API request
|
22
|
+
#
|
23
|
+
# ==== Attributes
|
24
|
+
# * +apiEndpoint+ - API end point
|
25
|
+
# * +headerHash+ - Hash definition of header options
|
26
|
+
# * +queryHash+ - Hash definition of query options
|
27
|
+
# ==== Examples
|
28
|
+
#
|
29
|
+
# [apiEndpoint]
|
30
|
+
# - Given the complete browser's uri : https://www.company.com:8080/api/endpoint1/endpoint1_1
|
31
|
+
# - given the base uri : https://www.company.com:8080
|
32
|
+
# - then endpoint is : api/endpoint1/endpoint1_1
|
33
|
+
#
|
34
|
+
# [headerHash]
|
35
|
+
# - my_header: {
|
36
|
+
# "Key1" => "value1",
|
37
|
+
# "key2" => "value2"
|
38
|
+
# }
|
39
|
+
#
|
40
|
+
# [headerQuery]
|
41
|
+
# - my_query {
|
42
|
+
# "key1" => "value1",
|
43
|
+
# "key2" => "value2"
|
44
|
+
# }
|
45
|
+
def getRequest(apiEndpoint,headerHash,queryHash)
|
46
|
+
@header_hash = headerHash
|
47
|
+
@query_hash = queryHash
|
48
|
+
request_uri = @base_uri +"/" + apiEndpoint
|
49
|
+
@request_options = {headers: @header_hash, query: @query_hash }
|
50
|
+
result = HTTParty.get(request_uri,@request_options)
|
51
|
+
return result
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set request header hash
|
55
|
+
#
|
56
|
+
# ==== Attributes
|
57
|
+
# * +headerHash+ - Hash definition of header options
|
58
|
+
# ==== Examples
|
59
|
+
#
|
60
|
+
# [headerHash]
|
61
|
+
# - my_header: {
|
62
|
+
# "Key1" => "value1",
|
63
|
+
# "key2" => "value2"
|
64
|
+
# }
|
65
|
+
def setHeader(headerHash)
|
66
|
+
@header_hash = headerHash
|
67
|
+
end
|
68
|
+
|
69
|
+
# Set request query hash
|
70
|
+
#
|
71
|
+
# ==== Attributes
|
72
|
+
# * +queryHash+ - Hash definition of query options
|
73
|
+
# ==== Examples
|
74
|
+
#
|
75
|
+
# [queryHash]
|
76
|
+
# - my_query: {
|
77
|
+
# "Key1" => "value1",
|
78
|
+
# "key2" => "value2"
|
79
|
+
# }
|
80
|
+
def setQuery(queryHash)
|
81
|
+
@query_hash = queryHash
|
82
|
+
end
|
83
|
+
|
84
|
+
# Set request body hash
|
85
|
+
#
|
86
|
+
# ==== Attributes
|
87
|
+
# * +bodyHash+ - Hash definition of body options
|
88
|
+
# ==== Examples
|
89
|
+
#
|
90
|
+
# [bodyHash]
|
91
|
+
# - my_body: {
|
92
|
+
# "Key1" => "value1",
|
93
|
+
# "key2" => "value2"
|
94
|
+
# }
|
95
|
+
def setBody(bodyHash)
|
96
|
+
@body_hash = bodyHash
|
97
|
+
end
|
98
|
+
|
99
|
+
# Request for API authentication
|
100
|
+
#
|
101
|
+
# ==== Attributes
|
102
|
+
# * +authentication_endpoint+ - API authentication end point
|
103
|
+
# * +username+ - username
|
104
|
+
# * +password+ - password
|
105
|
+
# ==== Examples
|
106
|
+
# * [authentication_endpoint]
|
107
|
+
# - given the complete uri : https://www.company.com/auth
|
108
|
+
# - the base uri is : https://www.company.com
|
109
|
+
# - the authentication endpoint is : auth
|
110
|
+
def authenticate(authentication_endpoint, username, password)
|
111
|
+
authentication_uri = @base_uri + "/" + authentication_endpoint
|
112
|
+
authentication_options = {headers: @header_hash, body: @body_hash}
|
113
|
+
authentication_result = HTTParty.post(authentication_uri, authentication_options)
|
114
|
+
if authentication_result.code == 200 # success
|
115
|
+
@auth_token = authentication_result.parsed_response["token"]
|
116
|
+
@auth_value = "Bearer " + @auth_token
|
117
|
+
@header_hash = {
|
118
|
+
"authorization" => @auth_value
|
119
|
+
}
|
120
|
+
result = true
|
121
|
+
else
|
122
|
+
result = false
|
123
|
+
end
|
124
|
+
return result
|
125
|
+
end
|
126
|
+
end # end- APIConnector
|
127
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: AvrijAnalyticsUtility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Dalisay
|
@@ -120,8 +120,7 @@ files:
|
|
120
120
|
- bin/console
|
121
121
|
- bin/setup
|
122
122
|
- lib/AvrijAnalyticsUtility.rb
|
123
|
-
- lib/AvrijAnalyticsUtility/
|
124
|
-
- lib/AvrijAnalyticsUtility/EyesoverConnection.rb
|
123
|
+
- lib/AvrijAnalyticsUtility/APIConnector.rb
|
125
124
|
- lib/AvrijAnalyticsUtility/version.rb
|
126
125
|
homepage: https://github.com/Avrij/AvrijAnalyticsUtilityGem.git
|
127
126
|
licenses:
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'httparty'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
|
6
|
-
class AvrijAnalyticsUtility::APIConnection
|
7
|
-
|
8
|
-
attr_accessor :auth_token, :auth_value, :header_hash, :query_hash, :username, :password, :base_uri, :request_option
|
9
|
-
|
10
|
-
# Constructor
|
11
|
-
def initialize(base_uri)
|
12
|
-
@auth_token = nil
|
13
|
-
@auth_value = nil
|
14
|
-
@header_hash = nil
|
15
|
-
@query_hash = nil
|
16
|
-
@username = nil
|
17
|
-
@password = nil
|
18
|
-
@base_uri = base_uri
|
19
|
-
@request_options = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
# API Endpoint Request
|
23
|
-
#
|
24
|
-
# ==== Attributes
|
25
|
-
#
|
26
|
-
# * +param_api_endpoint+ - API endpoint
|
27
|
-
# * +param_header_hash+ - Header hash
|
28
|
-
# * +param_query_hash+ - Query hash
|
29
|
-
#
|
30
|
-
# ==== Return
|
31
|
-
#
|
32
|
-
# * returns get request OBJECT
|
33
|
-
#
|
34
|
-
# ==== Example
|
35
|
-
# * https://www.company.com/api/endpoint1/endpoint1_1
|
36
|
-
# param_api_endpoint = api/endpoint1/endpoint1_1
|
37
|
-
# ====
|
38
|
-
def getAPI_Request(param_api_endpoint,param_header_hash,param_query_hash)
|
39
|
-
api_request_uri = self.base_uri + param_api_endpoint
|
40
|
-
self.header_hash = param_header_hash
|
41
|
-
self.request_options = {headers: param_header_hash, query: param_query_hash}
|
42
|
-
getRequest_result = HTTParty.get(api_request_uri,@request_options)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the social media post
|
46
|
-
#
|
47
|
-
# ==== Attributes
|
48
|
-
#
|
49
|
-
# * +param_api_uri+ - API end point
|
50
|
-
# * +param_query_hash+ - query hash
|
51
|
-
#
|
52
|
-
# ==== Examples
|
53
|
-
#
|
54
|
-
# +parap_api_uri+
|
55
|
-
#
|
56
|
-
# https://www.company.com:8080/api/endPoint
|
57
|
-
#
|
58
|
-
# +param_query_hash+
|
59
|
-
#
|
60
|
-
# query_values = {
|
61
|
-
# "key1" => "value1",
|
62
|
-
# "key2" => "value2"
|
63
|
-
# }
|
64
|
-
#
|
65
|
-
# ====
|
66
|
-
def getSocialMediaPost(param_api_uri,param_query_hash)
|
67
|
-
@OPTIONS = {query: param_query_hash , headers:@HEADER_VALUE}
|
68
|
-
getRequest_result = HTTParty.get(param_api_uri,@OPTIONS)
|
69
|
-
return getRequest_result
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# Returns all entities
|
75
|
-
#
|
76
|
-
# ==== Attributes
|
77
|
-
#
|
78
|
-
# * +param_api_uri_+ - API end point
|
79
|
-
#
|
80
|
-
# ==== Return
|
81
|
-
#
|
82
|
-
# * returns get request OBJECT
|
83
|
-
#
|
84
|
-
# ==== Examples
|
85
|
-
#
|
86
|
-
# +parap_api_uri+
|
87
|
-
#
|
88
|
-
# https://www.company.com:8080/api/endPoint
|
89
|
-
#
|
90
|
-
# ====
|
91
|
-
def getAllEntities(param_api_uri)
|
92
|
-
@OPTIONS = {headers:@HEADER_VALUE}
|
93
|
-
getRequest_result = HTTParty.get(param_api_uri,@OPTIONS)
|
94
|
-
return getRequest_result
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
# Authenticate
|
99
|
-
#
|
100
|
-
# ==== Attributes
|
101
|
-
#
|
102
|
-
# * +param_username+ - Username
|
103
|
-
# * +param_password+ - Password
|
104
|
-
# * +param_api_uri+ - API endpoint for authentication
|
105
|
-
#
|
106
|
-
# ==== Return
|
107
|
-
#
|
108
|
-
# * returns TRUE if authentication is successful
|
109
|
-
#
|
110
|
-
# ====
|
111
|
-
def authenticate(param_username,param_password,param_api_uri)
|
112
|
-
@options = {
|
113
|
-
headers: {
|
114
|
-
"Authorization" => "Bearer undefined"
|
115
|
-
},
|
116
|
-
body: {
|
117
|
-
"username" => param_username,
|
118
|
-
"password" => param_password
|
119
|
-
}
|
120
|
-
}
|
121
|
-
auth_response = HTTParty.post(param_api_uri,@options)
|
122
|
-
@AUTH_TOKEN = auth_response.parsed_response["token"]
|
123
|
-
@AUTH_VALUE = "Bearer " + @AUTH_TOKEN
|
124
|
-
@HEADER_VALUE = {
|
125
|
-
"authorization" => @AUTH_VALUE
|
126
|
-
}
|
127
|
-
return !@AUTH_VALUE.nil?
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
end
|