Code Monkey home page Code Monkey logo

suai's Introduction

SUAI

CI Status Version License Platform

SUAI is a lightweight and very simple library for working with contents of Saint Petersburg State University of Aerospace Instrumentation. Using this library you can:

  • Obtain schedule of groups, teachers and auditories referenced from scheduling site;
  • Obtain university news.

This library used in Official SUAI app "Спутник ГУАП".

Example

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

Installation

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

pod 'SUAI'

Usage

Schedule

If you know name of entity and it's type, use:

- (void)loadScheduleFor:(NSString *)entityName
                 ofType:(Entity)type
                success:(void (^) (SUAISchedule *schedule))schedule
                   fail:(void (^) (__kindof SUAIError *error))error;

or if you have SUAIEntity object of entity, use:

- (void)loadScheduleFor:(SUAIEntity *)entity
                success:(void (^) (SUAISchedule *schedule))schedule
                   fail:(void (^) (__kindof SUAIError *error))error;

Above methods are similar, if schedule have been obtained without errors, success block will be called. In any cases fail block is to your service :). Example how to load schedule of type: Group with name "1741":

Objective-C

[[[SUAI instance] schedule] loadScheduleFor:@"1741" ofType:EntityTypeGroup success:^(SUAISchedule *schedule) {
        NSLog(@"OK: %@", schedule);
} fail:^(__kindof SUAIError *error) {
        NSLog(@"error: %@", error.description)
}];

Swift

SUAI.instance().schedule.loadSchedule(for: "1741", of: .group, success: { (schedule) in
    print("OK: \(schedule)")
}) { (error) in
    print("error: \(error.description)")
}

News

For load available news preview use this method:

- (void)loadAllNews:(void (^) (NSArray<SUAINews *>* news))success
               fail:(void (^) (SUAIError *err))error;

If you want to load concrete news use:

- (void)loadNews:(NSString *)newsID
         success:(void (^) (SUAINews *news))success
            fail:(void (^) (SUAIError *err))error;

Where newsID is a part of url stored in property publicationId of SUAINews object.

Notifications

Library also contain notification constants. Subscribe on it if you need to react on it's changing:

  • kSUAIReachabilityNotification If you subscribed on this notification constant, you will be able to handle internet reachability changes (e.g. device is offline or connected via Wi-fi or LTE). In notification object you will get NSNumber contains bool value with reachability status. Example: Somewhere you subscribed on notification:
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(p_internetReachabilityChanged:)
                                             name:kSUAIReachabilityNotification object:nil];

And in method p_internetReachabilityChanged you can check reachability status:

- (void)p_internetReachabilityChanged:(NSNotification *)notification {
    BOOL isReachable = [(NSNumber *)[notification object] boolValue];
    NSLog(@"internet is reachable: %ld", isReachable);
}
  • kSUAIWeekTypeObtainedNotification Constant will notify when SUAI loaded current week type of week.
  • kSUAIEntityLoadedNotification Before you be able to load schedule, it's necessary to load all available codes. This contant will notify when all codes are loaded and ready to work.

Important

Don't forget to allow arbitrary loads!

  1. Go to plist file;
  2. In information property list add new key "App Transport Security Settings";
  3. In added dictionary add key "Allow Arbitrary Loads" and set value to YES.

Requirements

  • Xcode
  • Objective-C
  • iOS 9.0 or higher

Author

Victor Volkov, [email protected]

License

SUAI is available under the MIT license. See the LICENSE file for more info.

suai's People

Contributors

vvlkv avatar

Stargazers

Leonid Shatunov avatar

Watchers

 avatar

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.