Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EyreFree committed May 11, 2023
1 parent 4d82499 commit 0920e19
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

-----

## [0.2.0](https://github.com/EyreFree/FakeUserAgent.swift/releases/tag/0.2.0) (2023-05-12)

- Add synchronization method.

---

## [0.1.0](https://github.com/EyreFree/FakeUserAgent.swift/releases/tag/0.1.0) (2023-05-12)

- First public release.
2 changes: 1 addition & 1 deletion Example/FakeUserAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
AAA85C5CF6F160C508C80FC7 /* FakeUserAgent.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = FakeUserAgent.podspec; path = ../FakeUserAgent.podspec; sourceTree = "<group>"; };
AAA85C5CF6F160C508C80FC7 /* FakeUserAgent.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = FakeUserAgent.podspec; path = ../FakeUserAgent.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
E29D14F02B040FE1014F2485 /* Pods_FakeUserAgent_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FakeUserAgent_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E33999D8FC2C06E4D6D1A27D /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
E539CD91653A26E3864C5283 /* Pods-FakeUserAgent_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FakeUserAgent_Example.release.xcconfig"; path = "Target Support Files/Pods-FakeUserAgent_Example/Pods-FakeUserAgent_Example.release.xcconfig"; sourceTree = "<group>"; };
Expand Down
2 changes: 2 additions & 0 deletions Example/FakeUserAgent/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

print(FakeUserAgent.shared.pickOne(browser: .opera) ?? "Not found" + "\n")

FakeUserAgent.shared.pickALot(count: 5, browser: .chrome, filter: { userAgent in
return userAgent.contains("Macintosh; Intel Mac OS X 10_")
}, completion: { result in
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use_frameworks!

platform :ios, '10.0'
platform :ios, '11.0'

target 'FakeUserAgent_Example' do
pod 'FakeUserAgent', :path => '../'
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- FakeUserAgent (0.1.0)
- FakeUserAgent (0.2.0)

DEPENDENCIES:
- FakeUserAgent (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
FakeUserAgent: 66ee5e4cfaae91288635f1a66498d2dafc422ac0
FakeUserAgent: a42bf4b041b4431d95a02d6fcf89f9c143fbffbf

PODFILE CHECKSUM: 906adbc7198d54ca8ce6e35872d5f5c56937a6c5
PODFILE CHECKSUM: 1cbdb7fe9ac2aa2e95a434ce8e80f4e6a0967cf0

COCOAPODS: 1.12.1
2 changes: 1 addition & 1 deletion FakeUserAgent.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FakeUserAgent'
s.version = '0.1.0'
s.version = '0.2.0'
s.summary = 'FakeUserAgent in swift.'

s.description = <<-DESC
Expand Down
38 changes: 38 additions & 0 deletions FakeUserAgent/Classes/FakeUserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,41 @@ public class FakeUserAgent {
return BrowsersModel()
}()

public func pickOne(browser: BrowserOptions = .all, filter: ((String) -> Bool)? = nil) -> String? {
return pickALot(count: 1, browser: browser, filter: filter).first
}

public func pickALot(count: Int, browser: BrowserOptions = .all, filter: ((String) -> Bool)? = nil) -> [String] {
var loop: [(/*result: */[String], /*userAgents: */[String], /*browser: */BrowserOptions)] = [
([String](), userAgents.chrome, BrowserOptions.chrome),
([String](), userAgents.opera, BrowserOptions.opera),
([String](), userAgents.firefox, BrowserOptions.firefox),
([String](), userAgents.safari, BrowserOptions.safari),
([String](), userAgents.edge, BrowserOptions.edge),
([String](), userAgents.internetExplorer, BrowserOptions.internetExplorer),
]

for (index, (_, loopUserAgents, loopBrowser)) in loop.enumerated() {
if browser.contains(loopBrowser) {
if let filter = filter {
loop[index].0 = loopUserAgents.filter({ filter($0) })
} else {
loop[index].0 = loopUserAgents
}
}
}
let result: [String] = loop.reduce(into: [], { $0 += $1.0 })
if result.count <= count {
return result
} else if 1 == count {
let randomIndex: Int = Int.random(in: 0..<result.count)
return [result[randomIndex]]
} else {
let randomElements: [String] = Array(result.shuffled().prefix(count))
return randomElements
}
}

public func pickOne(browser: BrowserOptions = .all, filter: ((String) -> Bool)? = nil, completion: ((String?) -> Void)?) {
pickALot(count: 1, browser: browser, filter: filter) { results in
completion?(results.first)
Expand Down Expand Up @@ -109,6 +144,9 @@ public class FakeUserAgent {
let result: [String] = loop.reduce(into: [], { $0 += $1.0 })
if result.count <= count {
completion?(result)
} else if 1 == count {
let randomIndex: Int = Int.random(in: 0..<result.count)
completion?([result[randomIndex]])
} else {
let randomElements: [String] = Array(result.shuffled().prefix(count))
completion?(randomElements)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Once you have your Swift package set up, adding FakeUserAgent as a dependency is

```swift
dependencies: [
.package(url: "https://github.com/EyreFree/FakeUserAgent.swift", .upToNextMinor(from: "0.1.0"))
.package(url: "https://github.com/EyreFree/FakeUserAgent.swift", .upToNextMinor(from: "0.2.0"))
]
```

Expand Down

0 comments on commit 0920e19

Please sign in to comment.