Skip to content

Commit

Permalink
added Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dustedrob committed Sep 20, 2016
1 parent 3ed3a5f commit 7165b40
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/org/jstrava/connector/JStrava.java
Expand Up @@ -4,6 +4,7 @@
import org.jstrava.entities.athlete.Athlete;
import org.jstrava.entities.club.Club;
import org.jstrava.entities.gear.Gear;
import org.jstrava.entities.route.Route;
import org.jstrava.entities.segment.Bound;
import org.jstrava.entities.segment.Segment;
import org.jstrava.entities.segment.SegmentEffort;
Expand Down Expand Up @@ -64,6 +65,11 @@ public interface JStrava {
public Club findClub(int id);
public List<Club> getCurrentAthleteClubs();
public Gear findGear(String id);

public Route findRoute(int routeId);

public List<Route> findAthleteRoutes(int athleteId);

public Segment findSegment(long segmentId);
public List<Segment> getCurrentStarredSegment();
public SegmentLeaderBoard findSegmentLeaderBoard (long segmentId);
Expand Down
23 changes: 23 additions & 0 deletions src/org/jstrava/connector/JStravaV3.java
Expand Up @@ -6,6 +6,7 @@
import org.jstrava.entities.athlete.Athlete;
import org.jstrava.entities.club.Club;
import org.jstrava.entities.gear.Gear;
import org.jstrava.entities.route.Route;
import org.jstrava.entities.segment.Bound;
import org.jstrava.entities.segment.Segment;
import org.jstrava.entities.segment.SegmentEffort;
Expand Down Expand Up @@ -525,6 +526,28 @@ public Gear findGear(String id) {
return gear;
}

@Override
public Route findRoute(int routeId) {

String URL="https://www.strava.com/api/v3/route/"+routeId;
String result=getResult(URL);

Route route= gson.fromJson(result,Route.class);

return route;

}

@Override
public List<Route> findAthleteRoutes(int athleteId) {
String URL="https://www.strava.com/api/v3/athletes/"+athleteId+"/routes";
String result=getResult(URL);

Route[] routesArray=gson.fromJson(result,Route[].class);
List<Route>athleteRoutes= Arrays.asList(routesArray);
return athleteRoutes;
}

@Override
public Segment findSegment(long segmentId) {
String URL="https://www.strava.com/api/v3/segments/"+segmentId;
Expand Down
151 changes: 151 additions & 0 deletions src/org/jstrava/entities/route/Route.java
@@ -0,0 +1,151 @@
package org.jstrava.entities.route;

import org.jstrava.entities.activity.Polyline;
import org.jstrava.entities.athlete.Athlete;
import org.jstrava.entities.segment.Segment;

import java.util.ArrayList;

/**
* Created by roberto on 18/08/16.
*/
public class Route {

private int id;
private int resource_state;
private String name;
private String description;
private Athlete athlete;
private float distance;
private float elevation_gain;
private Polyline map;
private int type;
private int sub_type;
private boolean PRIVATE;
private boolean starred;
private long timestamp;
private ArrayList<Segment> segments = new ArrayList<>();

public Route() {
}

@Override
public String toString() {
return "Route{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getResource_state() {
return resource_state;
}

public void setResource_state(int resource_state) {
this.resource_state = resource_state;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Athlete getAthlete() {
return athlete;
}

public void setAthlete(Athlete athlete) {
this.athlete = athlete;
}

public float getDistance() {
return distance;
}

public void setDistance(float distance) {
this.distance = distance;
}

public float getElevation_gain() {
return elevation_gain;
}

public void setElevation_gain(float elevation_gain) {
this.elevation_gain = elevation_gain;
}

public Polyline getMap() {
return map;
}

public void setMap(Polyline map) {
this.map = map;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public int getSub_type() {
return sub_type;
}

public void setSub_type(int sub_type) {
this.sub_type = sub_type;
}

public boolean isPRIVATE() {
return PRIVATE;
}

public void setPRIVATE(boolean PRIVATE) {
this.PRIVATE = PRIVATE;
}

public boolean isStarred() {
return starred;
}

public void setStarred(boolean starred) {
this.starred = starred;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public ArrayList<Segment> getSegments() {
return segments;
}

public void setSegments(ArrayList<Segment> segments) {
this.segments = segments;
}
}
3 changes: 2 additions & 1 deletion test/org/jstrava/connector/JStravaV3Test.java
Expand Up @@ -7,6 +7,7 @@
import org.jstrava.entities.athlete.Athlete;
import org.jstrava.entities.club.Club;
import org.jstrava.entities.gear.Gear;
import org.jstrava.entities.route.Route;
import org.jstrava.entities.segment.*;
import org.jstrava.entities.stream.Stream;
import org.junit.After;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class JStravaV3Test {
@Before
public void setUp() throws Exception {

/*REMEMBER TO SETUP YOUR API ACCESS CODE AND OTHER PARAMETERS HERE!!!*/
/*todo: REMEMBER TO SETUP YOUR API ACCESS CODE AND OTHER PARAMETERS HERE TO RUN THE TESTS!!!*/

accessToken ="";
athleteId=0;
Expand Down

0 comments on commit 7165b40

Please sign in to comment.