Git Product home page Git Product logo

xing-android-sdk's Introduction

THIS REPO HAS BEEN ARCHIVED, MAINTENANCE OF THE SDK HAS BEEN DISCONTINUED

If you want to keep using the SDK Client, even though it is not maintained, consider that it can only be used if you already have an application registered at dev.xing.com

  • Meaning you are already in posession of a ConsumerKey + ConsumerSecret pair since it is no longer possible to register a new application

XING API Client for Java/Android


Build Status Maven Central

Add all the power of the XING platform to your app.

This library provides a java implementation of a network layer infrastructure required to access the XING Web Services. It's center class the XingApi allows users to access resources that reflect the XING API public, documentation for which can be found here.

How to get Started

1.1. For Java projects

Add the XING API Client as a dependency:

Either through Gradle:

compile 'com.xing.api:api-client:x.y.z'

or by using Maven:

<dependency>
  <groupId>com.xing.api</groupId>
  <artifactId>api-client</artifactId>
  <version>x.y.z</version>
</dependency>

1.2. For Android projects

For Android we made an additional step and implemented an oauth helper library, to simplify Login with XING implementation in your app. To benefit from this library just add the following dependency in you gradle build file:

compile 'com.xing.api:android-oauth:x.y.z'

Snapshots of the development version are available in Sonatype's snapshots repository.

2. Add OAuth credentials to your project

Add your OAuth Consumer Key and OAuth Consumer Secret to your project.

The OAuth information can be obtained after registering a new app on https://dev.xing.com/applications

For Android projects you can add the keys to your local.properties file:

	oauth_consumer_secret=xxxxxxxxxxxxxxxxxxxx
	oauth_consumer_key=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
	sdk.dir=/path/to/sdk

You are also free to provide this information in any other way. For example using Preferences or a helper class containing the API credentials as CONSTANTS.

3. Build your first app (Android Example)

To build your Android app with the XING API Client check out the Get started page

Based on Okio

The XING API Client is fully based on the Okio stack. We use OkHttp for networking, Moshi for Json parsing, and the request building/execution system is a fork of Retrofit.

Borrows from Retrofit

If you are using Retrofit as an HTTP client, you will find this api to be very familiar.
Here are somme key differences and similarities are:

  • XingApi - This class acts as a key entry point and resource provider (Similar to Retrofit in Retrofit 2.)
  • Resource - Namespace/Api provider class. We try to reflect the public api documentation in such a way that every resource section will have it's own Resource class implementation.
  • CallSpec<RT, ET> - Similar to Call<T> in Retrofit, but with a few key deference's:
    • CallSpec is aware of both return types RT for success and ET for error responses. And will parse them out of the box.
    • CallSpec allows users to alter the underlying request to a certain degree (you can add query or form params, as well as completely change the request body. This will become useful for those who want to benefit form optional request parameters accepted by XING WEB Services.
    • In addition to #execute() and #enqueue() methods CallSpec provides #stream() and #rawStream() if you are into RxJava (WARNING: usage of these methods will require you to have RxJava in your classpath).

Contributing

How to contribute

If you have an idea how to improve this library, feel free to either suggest your idea using the issues, or send us a Pull Request. If you do the latter please make sure you observe the rules for contributing below.

  1. Fork this repository.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Make sure to cover your new feature with sufficient unit tests.
  5. Create a new Pull Request.
  6. Wait for us to review your feature, discuss internal and eventually accept your Pull Request.
  7. Enjoy using your feature inside the XING API Client.

Contact

If you have any problems or feedback, feel free to contact us:

Dependencies

License

Copyright (C) 2016 XING SE (http://xing.com/)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

xing-android-sdk's People

Contributors

aballano avatar akreul avatar ciprianu avatar cmonfortep avatar danielgoncharov avatar david-varela avatar dhartwich1991 avatar dmccormack avatar jacopocafarelli avatar juliagarrigos avatar mandicabrito avatar mostafazakaria avatar mydogtom avatar q231950 avatar realdadfish avatar ricamgar avatar serj-lotutovici avatar shyish avatar vgrec avatar yayaa 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

Watchers

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

xing-android-sdk's Issues

Separate CallSpec tests by scope.

Currently the CallSpecTest is a mess of tests with deferent scopes. Would be nice to separate the tests. For example like so:

  • CallSpecBuilderTest - should contain everything related to the builder api
  • CallSpecTest - should contain everything related to the CallSpec api (exept for it's reactive apis)
  • CallSpecRxTest - should contain everything related to CallSpec's reactive apis.

Consider making HttpException not final / define methods in an interface

In order to test clients receiving a possible exception of this type there's no way to mock HttpException since is final and the same with Response (apart from having all fields package-protected), so instead of:

HttpException mock = mock(HttpException.class);
when(mock.code()).thenReturn(...);
when(mock.message()).thenReturn(...);

There's no possible way to create a mock/testing instance.

Fork retrofits way of creating request methods.

Currently each resource declares a method, that returns a CallSpec, each declared method uses helper factory methods to build the resulting spec. This created multiple problems with the api flexibility, and is is not type safe. A good approach to adopt the reflection based method, to provide an implementation for each method like Retrofit does, but in a more restricted fashion:

  • Allow returning only CallSpec
  • Support only GET, PUT, POST and DELETE requests

Allow callers to set an OkHttpClient.

At the moment, we are duplicating some methods exposed by OkHttpClient.Builder when we construct the instance of XingApi. A better approach would be to just expose a XingApi.Builder.client() or any other method, and leave the rest on the shoulders of the library user.

Drop XingOAuthCallback?

Currently the api for com.xing.api.oauth.XingOAuth is a little bit misleading. The XingOAuthCallback implies the the response will be processed asynchronously, when in reality it's just notifying the callback based on bundle coming from the authentication activity.

An alternative solution would be to make XingOAuth#onActivityResult return a XingOAuthResponse object, similar to com.xing.api.Response.

Upgrade to OkHttp 3.x

Version 2.0.0 will be released with OkHttp 2.7.x. We should consider adopting the 3.x api. This will allow us to benefit form the new connection pool implementation, and a more clear api.

One concern that I have, is related to the fact, that 3.x mostly introduced api changes with minor beneficial improvements. As I know 3.1 will fully drop support for url-connection and apache clients, which will improve the library's stable factor. Should we wait till that happens?

Change apiEndpoint

Hi,

It would be nice to be able to change the apiEndpoint from XingApi in runtime. Seems it should be possible by just providing a setter, which would set the new endpoint and invalidate the resource cache?

Cancelling a Task throws NetworkException

@serj-lotutovici

As is now
When running a Task and trying to cancel it with TaskManager.cancelExecution(...) a NetworkException is thrown, which basically makes impossible to differentiate from a real network issue (like no internet).

Should be
A different kind of exception should be thrown in order to do something specific or just ignore it.

Use Moshi for request response parsing

Use Moshi for request response parsing.

  • Use com.squareup.okhttp.Response to be able to access the raw response body (this will speedup parsing == no intermediate buffers between the parser and the response stream)
  • Depends on #11

Consider AutoValue for api client models.

Currently we are declaring all models manually. This creates an overhead for us when maintaining hashCode, equals() e.t.c. AutoValue will solve this problem for us.
Another pro is the new extension api of AutoValue which gives us a rich combination of possibilities.

AuthErrorCallback to rool them all

We need a single callback to notify the user that there was an authentication error. This callback should be huced up to XingApi and should be invoked when, and ONLY when the server sends us an un-authorized error.

The only question that remains, is should we allow the error to pass through the callback an not be "consumed"? Or should we make the caller completely un-aware of the error?

Split the non-primary resource classes into different packages.

Currently, each consumer who will add the api client as a dependency will add to it's class path the "full package" of supported resources. It makes sense to put each non-primary resource (like: JobsResource, EventsResource e.t.c.) to a separate module, which will be published as as standalone artefact.

Since each resource may require a specific data module and a custom json adapter, we need to think of a way which will allow users to specify those adapter, and/or additional configuration requirements.

GeoCode object should be null if invalid

When the api returns something like:

"geo_code":{"accuracy":null,"latitude":null,"longitude":null}

i.e. JobsResource#getJobById

the object gets created on parse time and contains -1,-1

the whole geoCode object should be null

Move to pure OkHttp request handling.

Since starting from Android KitKat the HttpUrlConnection implementation is using the OkHttp one, it makes sense to use OkHttp directly for network requests to avoid an additional implementation layer.

The feature must consist of:

  • Removing unnecessary RequestExecutor abstraction. All request manipulations must go through the request client.
  • Possibility to return raw responses for additional error and custom response handling
  • Consider possibility of removing the custom Request implementations
  • XingController must allow initialisation with a custom (or semi-custom) OkHttpClient

[Proposal] Consider using ThreeTen Backport instead of Calendar.

Currently we are using java.util.GregorianCalendar and java.util.Calendar for dates. This creates a layer of inconvenience, adds complexity to the data models and requires more effort for support.
Since Java8 there a new Time api was introduces, also know as JSR-310. But since we are targeting the Android platform we can not leverage from this rich and simple api. ThreeTen is a backport (written by the author of JSR-310) of that api to Java 6 and Java 7 with a (semi)active repo on Github::threetenbp.

Proposal:

  • Investigate the the backport library.
  • Analyse how much overhead it may add.
  • Replace all time related fields with ThreeTen classes?

[Architecture] Drop singletons

Since the current implementation is causing crashes doe to activity and application lifecycle, we need to avoid implementing the singleton pattern for the user. The design should promote the users to create a single object of the XingController via a simple builder and use it, instead of relying on us to do that.

This means:

  • No need for initialisation checks during instance access (this should be done only once by the builder during creation of the XingController). Short: If the instance was created by the builder, it is a valid one, loss of the instance will require to recreate it.
  • No need for the XingController#flush(), if the user whats to drop or re-initialise the object, he will only have to null the reference.
  • Allows users to inject the instance via a Dependency Injection framework, instead of loosing control of where the XingController#getInstance() is called.

Release 2.0.0 preparation

#27.09.2016

  • Add CHANGELOG.md
  • Javadocs for all public apis
  • Final cleanup
  • Rename LegalInformation to LegalInformationPreview

Create fields companion class from all data models.

When we move the data module generation to AutoValue #137, we can add a companion class generator, that will allow to build a user fields array. This is useful for resources like UserProfilesResource where the spec accepts model fields that have to be returned by the api.

This will reduce the probability runtime bugs, when using accessing a resource.

Things to keep in mind:

  • The api accepts nested field names as well, like field1.sub_field1.sub_sub_field2 the annotation processor will have to lookup for dependent builders.
  • The generated builder like class Fields should be something like:
@GenerateFields // Name not final.
abstract class XingUser {
  abstract class Fields {
    Fields field1();
    String[] build();
  }
}

Add RxJava Support

Users must be able to use RxJava and RxAndroid if this is there main way of handling asynchronous and data flow behaviour.

Conditions:

  • Execute requests returning an Observable
  • Users must provide RxJava in order to use this feature. The final aar file must not contain the actual dependency.

Improvement - Readme update

consider updating How to get Started section of the Readme.
Update gradle and maven sections with latest version number instead of x.y.z
This is a change of 2 lines on every release...

further consider that compile is deprecated in future releases of the android gradle plugin - maybe add the corresponding implementation maybe as:
For tools com.android.tools.build:gradle:3.0.0 use implementation 'com.xing.api:api-client:2.1.5'

thx in advance

Update android build tools.

It would be nice to use the latest android build tools.

  • android gradle plugin 1.5.0
  • compile sdk 23
  • build tools 23.0.2

RealCallSpec.stream ignores error type.

The stream() method lifts the rawStream() one with OperatorMapResponseToBodyOrError<RT, ET> but this operator is currently ignoring the error type ET in case of an error:

                @Override
                public void onNext(Response<RT, ET> response) {
                    if (response.isSuccessful()) {
                        child.onNext(response.body());
                    } else {
                        child.onError(new HttpException(response));
                    }
                }

                @Override
                public void onCompleted() {
                    child.onCompleted();
                }

                @Override
                public void onError(Throwable th) {
                    child.onError(th);
                }

Therefore the problem is that whenever the backend returns any kind of error onNext won't be called but so will onError with a throwable like java.io.IOException: 401 Unauthorized thus ignoring our error type and even the JSON with the proper reason.

Please correct me if I'm wrong. I'll investigate and try to make a PR tomorrow.

Fall back to String if error returned from api client is not matching HttpError

Right now the default error class that is returned from the api client is HttpError but when error json is not matching HttpError and there is no CallSpec::errorAs defined than the api client instead of HttpException will throw JsonSerializationException.

Expected behaviour:
HttpException with String as an field error

XingOAuthCallback

Hi,

why are you removing the XingOAuthCallback and replace it with calling onActivityResult() in the calling activity? Using the XingOAuthCallback makes it easier to separate the Xing calls from the normal logic, especially if the Xing login can be done on every activity of a project

Logout

Hi,

according to https://dev.xing.com/plugins/login_with/docs the Javascript-Library has the capability to do a logout on the server side ("xing.logout(callback, consumer_key);"). Is it also possible to do this with this sdk?

Best regards,
Boris

when setting xing callback uri it throws invalidarguementexception

Please see the attached image, i had been completely respecting XING url format as xing had mentioned in expected input as highlighted in red circle while the actual url highlighted in green circle.
img_07092016_163336

Can anyone please help resolve this error because i assume now XING sdk should not through illegal argument exception but still it does.

Thanks

[Proposal] Split the library in two artefacts.

This has a few benefits, as well as a few side-effects:

  • [+] Separate the auth activity and classes from the core of the sdk. Because the xing app implements it's own login mechanism we carry this code as loose weight.
  • [+] Possibility to provide the sdk as a jar and not an arr. This is a long shot, but what if java based application would also need to use an sdk, creating 2 separate libraries just doesn't make sense (will come back with more info on this)
  • [+] Minimize the wait of the artefact. Currently the sdk 1.0.0 is 186.07 K, in comparision retrofit is only 67K
  • [-/+] If we go with the java only track we lose the possibility of accessing some of android's apis, for a library that makes network calls and handles responses this may not be an issue, but what if the sdk will become something more?
  • [-] The sdk will have to be semi aware of the environment its running on, which means extra support for both platforms (java and android). We will also have to keep in mind that android is still in the java 7(6?) world and this restricts us from blindly moving to a newer java version, or even using some java 7 apis like try-with-resources (seriously Google couldn't back port that >_>)
  • [-] The module classes will may have to become just module classes with no awareness of some android interfaces (again adding to the plain java track)

For now it's just an idea an crazy mans head.

OAuth credentials

Hi,

I tried to play around with the API client, but I can't find my OAuth-Credentials. When I go to the page described in the README under "2. Add OAuth credentials to your project" I can't create an app to retrieve my credentials. Where do I have to click? It says "You don’t have any apps, ask your XING representative if you need to create one.", but there is no contact address or whatever. How can I get the client to work?

Regards

[api-client] Handle Content-Range

For some requests with pagination, XWS returns a Content-Range header which contains the current data offset + total values.
If the header is set, there are to possible outcomes:

  • Content-Range: items 2-23/130 (if the total is known)
  • Content-Range: items 3-34/* (if the total is unknown)

We need to parse this on a successful response, and pass this data inside a field of com.xing.api.Resposne.

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.