Git Product home page Git Product logo

yelp-ios's Introduction

Build Status

YelpAPI

To run the example project, clone the repo, and run pod install from the Example directory first.

This is a Cocoapod for the Yelp API. It'll simplify the process of consuming data from the Yelp API for developers using Objective-C or Swift. The library encompasses Search , Business, and Phone Search API functions.

Please remember to read and follow the Terms of Use and display requirements before creating your applications.

Installation

YelpAPI is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "YelpAPI"

Usage

Basic Usage

Before you can make any requests to the API, you must create a YLPClient by authorizing with the API using your app's ID and secret:

[YLPClient authorizeWithAppId:<id> secret:<secret> completionHandler:^
    (YLPClient *client, NSError *error) {
    // Save your newly authorized client
    self.client = client;
}];

Once you have a YLPClient object you can use the various search related function:

Search With Location
- (void)searchWithLocation:(NSString *)location
                      term:(nullable NSString *)term
                     limit:(NSUInteger)limit
                    offset:(NSUInteger)offset
                      sort:(YLPSortType)sort
         completionHandler:(YLPSearchCompletionHandler)completionHandler;

- (void)searchWithLocation:(NSString *)location
         completionHandler:(YLPSearchCompletionHandler)completionHandler;

Search With Coordinate
- (void)searchWithCoordinate:(YLPCoordinate *)coordinate
                        term:(nullable NSString *)term
                       limit:(NSUInteger)limit
                      offset:(NSUInteger)offset
                        sort:(YLPSortType)sort
           completionHandler:(YLPSearchCompletionHandler)completionHandler;

- (void)searchWithCoordinate:(YLPCoordinate *)coordinate
           completionHandler:(YLPSearchCompletionHandler)completionHandler;

Each interface provides a different way to query the Search API depending on the type of information that you have on hand. There are two different methods of querying the Search API, each of which accepts a different format for location input. Consequentially, there are two sets of functions in the clientlib to support calls into each version of the Search API. Each set of functions contains a version to call the API with only the required parameters, while another which accepts arguments for all optional parameters.

YLPSearchCompletionHandler is a block which takes a YLPSearch* and NSError* object as arguments. Upon successful completion of an API call the result will be returned in the YLPSearch* object, alternatively errors will be returned in the NSError* object.

Example Search Usage

[self.client searchWithLocation:@"San Francisco, CA" completionHandler:^
    (YLPSearch *search, NSError *error) {
    // Perform any tasks you need to here
}];

The YLPClient object will also provide access to the Business API, the relevant functions are:

- (void)businessWithId:(NSString *)businessId
     completionHandler:(YLPBusinessCompletionHandler)completionHandler;

YLPBusinessCompletionHandler is a block which takes a YLPBusiness* and an NSError* object as arguments. Upon successful completion of an API call the result will be returned in the YLPBusiness* object, alternatively errors will be returned in the NSError* object.

Example Business Usage

[self.client businessWithId:@"yelp-san-francisco" completionHandler:^
    (YLPBusiness *search, NSError *error) {
    // Perform any tasks you need to here
}];

The YLPClient object will also provide access to the Phone Search API, the relevant functions are:

- (void)businessWithPhoneNumber:(NSString *)phoneNumber
              completionHandler:(YLPPhoneSearchCompletionHandler)completionHandler;

YLPPhoneSearchCompletionHandler is a block which takes a YLPSearch* and an NSError* object as arguments. Upon successful completion of an API call the result will be returned in the YLPSearch* object, alternatively errors will be returned in the NSError* object.

Example Phone Search Usage

[self.client businessWithPhoneNumber:@"+14159083801" completionHandler:^
    (YLPSearch *search, NSError *error) {
    // Perform any tasks you need to here
}];

The YLPClient object also provides access to the Reviews API. The relevant methods are:

- (void)reviewsForBusinessWithId:(NSString *)businessId
               completionHandler:(YLPReviewsCompletionHandler)completionHandler;

- (void)reviewsForBusinessWithId:(NSString *)businessId
                          locale:(nullable NSString *)locale
               completionHandler:(YLPReviewsCompletionHandler)completionHandler;

Upon completion, the YLPReviewsCompletionHandler will be passed either a YLPBusinessReviews* object on success, or an NSError* object if there was an error.

Example Reviews Usage

[self.client reviewsForBusinessWithId:@"yelp-san-francisco" completionHandler:^
    (YLPBusinessReviews *reviews, NSError *error) {
    // Perform any tasks you need to here
}];

Responses

A Response object is a data structure returned after each successful API call. The objects are readily available to be used. They will contain all available response fields as documented in our API documentation.

Response objects returned by an API call may contain other Response objects. For example, the YLPSearch object contains an array of YLPBusiness objects as well. All Response objects can be found here

Contributing

  1. Fork it (http://github.com/yelp/yelp-ios/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

yelp-ios's People

Contributors

benasher44 avatar d9chen avatar dan98765 avatar iam10k avatar kennydang avatar peterwangnavisens avatar ssheldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yelp-ios's Issues

Add remaining YLPBusiness fields

There are more fields returned in the v3 business that aren't exposed by the current YLPBusiness:

  • is_closed
  • price
  • photos
  • hours

Note that these fields are only provided on the business returned from the business endpoint (i.e. not from search), so we might want to only provide them on a subclass of YLPBusiness used in the business endpoint's response.

Yelp API v3

Are there plans to migrate this library to V3 of the Yelp API? If so, what is the timeline like? Thanks!

Some search parameters cannot be specified

The following search parameters are documented but cannot be specified when making a search request:

  • category_filter
  • radius_filter
  • deals_filter
  • cc
  • lang
  • actionlinks

We should allow these to be specified!

Address array may include NSNull, violating type annotations

For example, if you lookup Philz Coffee the address array looks like: ["549 Castro St", <null>, ""]. I'm unclear on why there's a distinction between a null value and an empty string.

I feel like this will be an issue in more places. I did handle it for YLPUser.imageURL. In general, on APIv3 it looks like now we need to audit for nullability.

Businesses found; however, some locations are nil.

I ran into a recent problem that did not exist a few days ago. When I make an API call, it does go through successfully and I do get a list of business; however, some "locations" / "coordinates" belonging to a few businesses are nil and it is causing my code to break. I am confused as to how is it possible to find a business without location / coordinate info. As I already mentioned this did not happen before. I would really appreciate if someone could point out as to why this is happening?

Swift 3

Is there a version of this for Swift 3.0?

Change Pod author to Yelp

We should get this published on cocoapods.org!

I'll need to get the right accounts configured first.

YLPClient+Search uses NSUInteger rather than YLPSortType

The sort param of the YLPClient+Search methods takes an NSUInteger. Meanwhile, we have the nice YLPSort enum declaring what the possible values are, so it's type should be used instead of NSUInteger.

This will make it clearer what values can be passed, give better autocompletion, and improve swift compatibility.

Private headers aren't marked private

That line of the podspec was commented out in #4 because we ran into some issues:

Xcode didn't seem to like that I was importing these headers in my tests which are targeted against the YelpAPI example project as opposed to the Pods project.

The issue started occurring when I upgraded to xcode 7. On xcode 6 it didn't complain about importing these private headers.

Clean up repo structure

There are lots of .gitkeep files that should be removed (for example, the Pods/Assets directory is unused).

Also, I'd recommend moving the contents of "Pods" up one level. That will match more with the directory structure of our other pods, like YLTableView: https://github.com/Yelp/YLTableView/

.

.

Annotate designated and unavailable initializers

Currently, we don't annotate any initializers with NS_DESIGNATED_INITIALIZER or NS_UNAVAILABLE. This means that any of our objects can be constructed with plain init, breaking our invariants. This is especially bad in Swift, where if a nonnull property is uninitialized it can lead to undefined behavior.

For example, here's autocomplete recommending to me that I can construct a YLPClient without any tokens:
screen shot 2016-04-24 at 9 02 45 am

Allow saving and reusing access tokens

Access tokens last for a while (currently 180 days), but currently we don't expose any way to reuse an access token, so you must authorize a new one every time you wish to create a YLPClient.

A simple solution here could just be exposing the access token and expiry of a YLPClient and allowing users to create their own YLPClient from an access token, leaving storage up to them. A more comprehensive solution could involve storing the token in the keychain for users.

No way to construct a YLPCoordinate

Since we removed YLPCurrentLatLong, one must construct a YLPCoordinate when specifying their location. However, YLPCoordinate's initializer is private! So there's no way to construct a YLPCoordinate.

Yelp Fusion switch to API KEYS

"Prior to December 7, 2017 the API used OAuth 2.0 to authenticate requests to the API. In an effort to simplify authentication, starting March 1, 2018 the API will no longer use OAuth 2.0 for requests and will move over to only API Keys. The token endpoint will be deprecated March 1, 2018, at which point you will no longer be able to make requests to it. "
-source: Yelp (https://www.yelp.com/developers/documentation/v3/authentication#where-is-my-client-secret-going)

Is there an update to support this in the roadmap? We're closing in on less than a month with no announced update for the yelp-ios project.

Add Officially Supported Platforms to Documentation/README

The documentation right now does not mention what platforms yelp-ios supports. By the name one would think iOS only, but #42 indicates that macOS is supported as well. Is tvOS supported? watchOS? What versions of iOS are supported? Are the versions in the podspec up-to-date?

xcodebuild -sdk iphonesimulator errors out

Running on xcode 8.3

ld: framework not found Pods_YelpAPI
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

The following build commands failed:
Ld build/YelpAPI.build/Release-iphonesimulator/YelpAPI.build/Objects-normal/x86_64/YelpAPI normal x86_64
Ld build/YelpAPI.build/Release-iphonesimulator/YelpAPI.build/Objects-normal/i386/YelpAPI normal i386
(2 failures)

Missing Reviews in Search Results?

When I'm trying to load the reviews for a business it shows a "reviewCount" greater than 0 but the array of reviews has 0 objects. This is with all businesses I have attempted to view and I've confirmed that all of them did have reviews online.

screen shot 2016-07-17 at 05 34 54

Errors shouldn't use main bundle identifier for domain, may be nil and crash

We're using the main bundle identifier as our error domain. In a command-line app, [[NSBundle mainBundle] bundleIdentifier] is nil, which results in the following crash:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid domain=nil in -[NSError initWithDomain:code:userInfo:]'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff8d9234f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff86f2373c objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff8d98a4bd +[NSException raise:format:] + 205
    3   Foundation                          0x00007fff8bdd1012 -[NSError initWithDomain:code:userInfo:] + 118
    4   Foundation                          0x00007fff8bdd0f85 +[NSError errorWithDomain:code:userInfo:] + 59
    5   YelpAPI                             0x000000010053f41a __48-[YLPClient queryWithRequest:completionHandler:]_block_invoke + 554
    6   CFNetwork                           0x00007fff8eadb7f1 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 21
    7   CFNetwork                           0x00007fff8eadb0bf __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 302
    8   Foundation                          0x00007fff8bddc7d7 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
    9   Foundation                          0x00007fff8bddc495 -[NSBlockOperation main] + 100
    10  Foundation                          0x00007fff8bddab7a -[__NSOperationInternal _start:] + 654
    11  Foundation                          0x00007fff8bdd6b64 __NSOQSchedule_f + 194
    12  libdispatch.dylib                   0x0000000100559cc5 _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x000000010055f112 _dispatch_queue_drain + 351
    14  libdispatch.dylib                   0x0000000100566e24 _dispatch_queue_invoke + 557
    15  libdispatch.dylib                   0x000000010055ddab _dispatch_root_queue_drain + 1226
    16  libdispatch.dylib                   0x000000010055d8a5 _dispatch_worker_thread3 + 106
    17  libsystem_pthread.dylib             0x00000001005bc336 _pthread_wqthread + 1129
    18  libsystem_pthread.dylib             0x00000001005b9f91 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Also, using the identifier of the app using our API as the error domain seems wrong; Apple's docs say:

You can create your own error domains and error codes for use in your own frameworks, or even in your own applications. It is recommended that the string constant for the domain be of the form com.company.framework_or_app.ErrorDomain.

How about com.yelp.api.ErrorDomain for our error domain?

macOS Support

Any plans to add official macOS support? Is there anything stopping it from being used within a Mac app at present?

Add remaining YLPQuery parameters

There are more parameters accepted by the v3 search API that aren't supported by the current YLPQuery, including:

  • locale
  • price filter
  • open_now and open_at filters
  • attributes hot_and_new filter

Set up Travis CI

We should get the tests running automatically on pull requests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.