Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
18
Issues
18
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
bd5d80bc
Commit
bd5d80bc
authored
Jul 31, 2018
by
Alexander Prendetskiy
Committed by
Matija Obreza
Aug 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Bit.ly shortener
parent
154da81e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
src/main/java/org/genesys2/server/service/impl/BitlyURLShortener.java
...a/org/genesys2/server/service/impl/BitlyURLShortener.java
+61
-0
src/main/resources/application.properties
src/main/resources/application.properties
+6
-0
No files found.
src/main/java/org/genesys2/server/service/impl/BitlyURLShortener.java
0 → 100644
View file @
bd5d80bc
package
org.genesys2.server.service.impl
;
import
org.genesys2.server.service.UrlShortenerService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.URL
;
import
java.util.*
;
@Component
(
"bitlyURLShortener"
)
public
class
BitlyURLShortener
implements
UrlShortenerService
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
BitlyURLShortener
.
class
);
@Value
(
"${bitly.access.token}"
)
private
String
accessToken
;
@Value
(
"${bitly.group.guid}"
)
private
String
groupGuid
;
@Value
(
"${bitly.url.shortener}"
)
private
String
bitlyUrlShortener
;
private
RestTemplate
restTemplate
;
public
BitlyURLShortener
()
{
this
.
restTemplate
=
new
RestTemplate
();
}
@Override
public
String
shortenUrl
(
URL
url
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
set
(
"Authorization"
,
accessToken
);
Map
<
String
,
String
>
request
=
new
HashMap
<
String
,
String
>();
request
.
put
(
"long_url"
,
url
.
toString
());
request
.
put
(
"group_guid"
,
groupGuid
);
HttpEntity
<
Object
>
requestEntity
=
new
HttpEntity
<
Object
>(
request
,
headers
);
String
shortenUrl
=
null
;
try
{
LinkedHashMap
<
String
,
String
>
linkedHashMap
=
restTemplate
.
postForObject
(
bitlyUrlShortener
,
requestEntity
,
LinkedHashMap
.
class
);
shortenUrl
=
linkedHashMap
.
get
(
"id"
);
}
catch
(
final
RestClientException
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
return
shortenUrl
;
}
}
src/main/resources/application.properties
View file @
bd5d80bc
...
...
@@ -56,6 +56,12 @@ db.showSql=false
db.hbm2ddl
=
false
hibernate.dialect
=
org.hibernate.dialect.MySQL5InnoDBDialect
# bit.ly shortener
# TODO change access token and guid
bitly.access.token
=
xx
bitly.group.guid
=
xx
bitly.url.shortener
=
https://api-ssl.bitly.com/v4/shorten
google.api.key
=
AIzaSyBEvPuc8j5ps5GDQ3tdnTJaffKhfOdxFVc
google.url.shortener
=
https://www.googleapis.com/urlshortener/v1/url
news.menu.abbreviate.length
=
22
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment