Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Remove Alamofire. Close #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardoCardoso committed Jun 24, 2016
1 parent 9055c44 commit b3059dc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 31 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Change Log

#### 0.x Releases
- `0.0.x` Releases - [0.0.2](#002)
- `0.0.x` Releases - [0.0.2](#002) | [0.0.3](#003)

---

## [0.0.3]()
[^]: Released on ????-??-??.

[^]: #### Added
[^]: - Support for Carthage. #3
[^]: - Added by [Leonardo Cardoso](https://github.com/LeonardoCardoso).
[^]: - Support for Swift Package Manager. #3
[^]: - Added by [Leonardo Cardoso](https://github.com/LeonardoCardoso).

#### Removed
- Alamofire. #6
- Removed by [Leonardo Cardoso](https://github.com/LeonardoCardoso).


## [0.0.2](https://github.com/LeonardoCardoso/Swift-Link-Preview/releases/tag/0.0.2)
Released on 2016-06-26.

Expand Down
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ platform :ios, '8.0'

target 'SwiftLinkPreview' do
use_frameworks!
pod 'Alamofire', '~> 3.4'
end
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

It makes a preview from an url, grabbing all the information such as title, relevant texts and images.

[![CocoaPods](https://img.shields.io/cocoapods/v/SwiftLinkPreview.svg?maxAge=2592000)]() [![CocoaPods](https://img.shields.io/cocoapods/l/SwiftLinkPreview.svg?maxAge=2592000)]() [![CocoaPods](https://img.shields.io/cocoapods/p/SwiftLinkPreview.svg?maxAge=2592000)]()
[![Platform](https://img.shields.io/cocoapods/p/SwiftLinkPreview.svg?maxAge=2592000)](https://img.shields.io/cocoapods/p/SwiftLinkPreview.svg?maxAge=2592000)
[![CocoaPods](https://img.shields.io/cocoapods/v/SwiftLinkPreview.svg?maxAge=2592000)](https://img.shields.io/cocoapods/v/SwiftLinkPreview.svg?maxAge=2592000)
[^]: [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-.svg?style=flat)](https://github.com/Carthage/Carthage)
[![LICENSE](https://img.shields.io/cocoapods/l/SwiftLinkPreview.svg?maxAge=2592000)](https://img.shields.io/cocoapods/l/SwiftLinkPreview.svg?maxAge=2592000)

**UTF-8** | **Extended UTF-8** |
:--:|:--:|
Expand All @@ -28,7 +31,7 @@ It makes a preview from an url, grabbing all the information such as title, rele

```ruby
use_frameworks!
pod 'SwiftLinkPreview', '~> 0.0.2'
pod 'SwiftLinkPreview', '~> 0.0.3'
```

### Manually
Expand Down
3 changes: 1 addition & 2 deletions SwiftLinkPreview.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ Pod::Spec.new do |s|
s.name = "SwiftLinkPreview"
s.summary = "It makes a preview from an url, grabbing all the information such as title, relevant texts and images."
s.requires_arc = true
s.version = "0.0.2"
s.version = "0.0.3"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Leonardo Cardoso" => "[email protected]" }
s.homepage = "https://github.com/LeonardoCardoso/Swift-Link-Preview"
s.source = { :git => "https://github.com/LeonardoCardoso/Swift-Link-Preview.git", :tag => "#{s.version}"}
s.framework = "UIKit"
s.dependency 'Alamofire', '~> 3.4'
s.source_files = "SwiftLinkPreview/**/*.{swift}"
s.resources = "SwiftLinkPreview/**/*.{swift}"

Expand Down
54 changes: 30 additions & 24 deletions SwiftLinkPreview/Classes/SwiftLinkPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import Alamofire

public class SwiftLinkPreview {

Expand All @@ -16,7 +15,8 @@ public class SwiftLinkPreview {
private var text: String!
private var url: NSURL!
private var result: [String: AnyObject] = [:]
private var request: Alamofire.Request?
private var task: NSURLSessionDataTask?
private let session = NSURLSession.sharedSession()

// MARK: - Constructor
public init() {
Expand Down Expand Up @@ -79,9 +79,9 @@ public class SwiftLinkPreview {
// Cancel request
public func cancel() {

if let request = self.request {
if let _ = self.task {

request.cancel()
self.task!.cancel()

}

Expand Down Expand Up @@ -120,27 +120,43 @@ extension SwiftLinkPreview {
// Unshorten URL by following redirections
private func unshortenURL(url: NSURL, completion: (NSURL) -> ()) {

request = Alamofire.request(.GET, url.absoluteString, parameters: [:])
.response { request, response, data, error in
self.task = session.dataTaskWithURL(url) { data, response, error in

print("\(response?.URL)")

if let finalResult = response?.URL {

if let finalResult = response?.URL {
if(finalResult.absoluteString == url.absoluteString) {

dispatch_async(dispatch_get_main_queue()){

if(finalResult.absoluteString == url.absoluteString) {

completion(url)

} else {

self.unshortenURL(finalResult, completion: completion)


}

} else {

self.task!.cancel()
self.unshortenURL(finalResult, completion: completion)

}

} else {

dispatch_async(dispatch_get_main_queue()){

completion(url)

}

}

}

if let _ = self.task {

self.task!.resume()

}

}
Expand All @@ -161,16 +177,6 @@ extension SwiftLinkPreview {

var htmlCode = try String(contentsOfURL: url)
htmlCode = htmlCode.extendedTrim
// htmlCode = htmlCode.deleteHTMLTag("script")
// htmlCode = htmlCode.deleteHTMLTag("link")
// htmlCode = htmlCode.deleteHTMLTag("path")
// htmlCode = htmlCode.deleteHTMLTag("style")
// htmlCode = htmlCode.deleteHTMLTag("iframe")
// htmlCode = htmlCode.deleteHTMLTag("a")
// htmlCode = htmlCode.deleteTagByPattern(Regex.aPattern)
// htmlCode = htmlCode.deleteHtmlComments()
// htmlCode = htmlCode.deleteCData()
// htmlCode = htmlCode.deleteInputs()

self.crawlMetaTags(htmlCode)
self.crawlTitle(htmlCode)
Expand Down
2 changes: 1 addition & 1 deletion SwiftLinkPreview/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.0.2</string>
<string>0.0.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit b3059dc

Please sign in to comment.