Skip to content

Commit

Permalink
Update Business model to match Yelp API v3’s JSON responses
Browse files Browse the repository at this point in the history
  • Loading branch information
tejen committed Jul 26, 2018
1 parent 6d84b61 commit 4b2caa4
Show file tree
Hide file tree
Showing 43 changed files with 296 additions and 17 deletions.
62 changes: 45 additions & 17 deletions Yelp/Business.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Business: NSObject {
let imageURL: URL?
let categories: String?
let distance: String?
let ratingImageURL: URL?
let ratingImage: UIImage?
let reviewCount: NSNumber?

init(dictionary: NSDictionary) {
Expand All @@ -30,26 +30,23 @@ class Business: NSObject {
let location = dictionary["location"] as? NSDictionary
var address = ""
if location != nil {
let addressArray = location!["address"] as? NSArray
if addressArray != nil && addressArray!.count > 0 {
address = addressArray![0] as! String
}

let neighborhoods = location!["neighborhoods"] as? NSArray
if neighborhoods != nil && neighborhoods!.count > 0 {
if !address.isEmpty {
address += ", "
let addressArray = location!["display_address"] as? NSArray
if addressArray != nil {
if addressArray!.count > 0 {
address = addressArray![0] as! String
}
if addressArray!.count > 1 {
address += ", " + (addressArray![1] as! String)
}
address += neighborhoods![0] as! String
}
}
self.address = address

let categoriesArray = dictionary["categories"] as? [[String]]
let categoriesArray = dictionary["categories"] as? [NSDictionary]
if categoriesArray != nil {
var categoryNames = [String]()
for category in categoriesArray! {
let categoryName = category[0]
let categoryName = category["title"] as! String
categoryNames.append(categoryName)
}
categories = categoryNames.joined(separator: ", ")
Expand All @@ -65,11 +62,42 @@ class Business: NSObject {
distance = nil
}

let ratingImageURLString = dictionary["rating_img_url_large"] as? String
if ratingImageURLString != nil {
ratingImageURL = URL(string: ratingImageURLString!)
let rating = dictionary["rating"] as? Double
if rating != nil {
switch rating {
case 1:
self.ratingImage = UIImage(named: "stars_1")
break
case 1.5:
self.ratingImage = UIImage(named: "stars_1half")
break
case 2:
self.ratingImage = UIImage(named: "stars_2")
break
case 2.5:
self.ratingImage = UIImage(named: "stars_2half")
break
case 3:
self.ratingImage = UIImage(named: "stars_3")
break
case 3.5:
self.ratingImage = UIImage(named: "stars_3half")
break
case 4:
self.ratingImage = UIImage(named: "stars_4")
break
case 4.5:
self.ratingImage = UIImage(named: "stars_4half")
break
case 5:
self.ratingImage = UIImage(named: "stars_5")
break
default:
self.ratingImage = UIImage(named: "stars_0")
break
}
} else {
ratingImageURL = nil
self.ratingImage = UIImage(named: "stars_0")
}

reviewCount = dictionary["review_count"] as? NSNumber
Expand Down
15 changes: 15 additions & 0 deletions Yelp/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions Yelp/Images.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_0.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_0.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_0.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_0.imageset/regular_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Yelp/Images.xcassets/stars_0.imageset/stars_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_1.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_1.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_1.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_1.imageset/regular_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Yelp/Images.xcassets/stars_1.imageset/stars_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_1half.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_1_half.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_1half.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_2.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_2.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_2.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_2.imageset/regular_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Yelp/Images.xcassets/stars_2.imageset/stars_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_2half.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_2_half.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_2half.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_3.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_3.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_3.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_3.imageset/regular_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Yelp/Images.xcassets/stars_3.imageset/stars_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_3half.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_3_half.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_3half.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_4.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_4.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_4.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_4.imageset/regular_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Yelp/Images.xcassets/stars_4.imageset/stars_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_4half.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_4_half.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_4half.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Yelp/Images.xcassets/stars_5.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "regular_5.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "stars_5.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Yelp/Images.xcassets/stars_5.imageset/regular_5.png
Binary file added Yelp/Images.xcassets/stars_5.imageset/stars_5.png

0 comments on commit 4b2caa4

Please sign in to comment.